-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path06_string.py
More file actions
77 lines (51 loc) · 2.04 KB
/
06_string.py
File metadata and controls
77 lines (51 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fruit = " apple " # assign a string to a variable
print (len ( fruit )) # print the length
print ("<" + fruit *10 + ">" ) # print the fruit 10 times and
# add delimiter symbols at the beginning and at the
# end of this long string
print("#######")
fruits = " apple " + " peach " + " melon " + " orange " # define a string
# with 4 fruits and concatenate them
print (len ( fruits )) # print the length
print (3* fruits ) # print it 3 times
print("#######")
fruits = " apple pear lemon orange kiwi " # 5 fruits separated by a
# space character
print ( fruits [::2]) # print characters every 2 steps
print ( fruits [::4]) # print characters every 4 steps
print ( fruits [:: -2]) # print using negative step
print ( fruits [:: -1]) # print using negative step
if "watermelon" == "waterMelon":
print('true')
else:
print('false')
d= "watermelon" == "waterMelon"
print(d)
g= "a" in "aladin"
print(g)
print('##################################################################')
j="pear***apple".isalnum()
print(j)
fruits = " pineapple lemon orange kiwi ", "djfhkdjfhkjdf"
print(fruits)
list_characters = list ( fruits )
print (len ( list_characters ))
characters_str = "". join ( list_characters ) # list into single string
print ( characters_str )
separated_str = characters_str . replace (" "," ->")
print ( separated_str )
print('333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333')
fruits = "orange ->kiwi -> banana -> pineapple -> lemon "
print ( fruits )
list_fruits = fruits . split (" ->") # Converting a single string into list
print ( list_fruits )
print("Lund"*60)
del list_fruits [0]
print ( list_fruits )
fruits_str = " ". join ( list_fruits ) # converts list into single string
print ( fruits_str )
print ( fruits_str . replace ("*"," "))
for char in fruits : # iterate the list so every time you find a
# vowel in it , the program prints the vowel
if char in " aeiou ":
print ( char )