-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstrings.py
More file actions
71 lines (56 loc) Β· 1.73 KB
/
strings.py
File metadata and controls
71 lines (56 loc) Β· 1.73 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
# What are strings?
# A string is a text any data under a single, double, triple quote can be considered as a string
# how long is a string, it a single character or many many pages
from itertools import count
letter = 'a'
print(len(letter))
word = 'python'
print(word, len(word))
sentence = 'Python is great'
print(sentence, len(sentence))
words = sentence.split()
print(len(words))
first_name = 'Hazrat'
print(first_name.lower())
print(first_name.upper())
# split(), lower, upper(), count(), starswith(), endswith(), title(), swapcase()
print('land' in 'Finland')
print('Tea' in ['Milk','Potatop','Tea','Sugar'])
country = 'Banglaseh'
print(country.startswith('Banlgla'))
print(country.endswith('Desh'))
first_name = 'Hazrat'
last_name = 'Ali'
age = 24
country = 'Bangladesh'
city = 'Dhaka'
full_name = first_name + ' ' + last_name
print(full_name)
print('My name is ' + full_name + '. ' + 'I live in ' + city + ', ' + country + '. ' + 'I am ' + str(age) + ' years old.')
print(f'My name is {full_name}. I live in {city}, {country}. I am {age} years old.')
a = 4
b = 3
print(f'The sum of {a} and {b} is {a + b}')
print('The sum of {} and {} is {}'.format(a, b, a + b))
print(f'The difference of {a} and {b} is {a - b}')
print(f'The product of {a} and {b} is {a * b}')
print(f'The division of {a} and {b} is {a / b :.3f}')
print(f'The modules of {a} and {b} is {a % b}')
print(f'The floor division of {a} and {b} is {a // b}')
print(f'The power of {a} and {b} is {a ** b}')
word = 'Python'
print(word[0])
print(word[1])
print(word[2])
print(word[3])
print(word[4])
print(word[5])
last_index = len(word) - 1
print(word[last_index])
print(word[-1])
print(word[-2])
print(word[4] == word[-2])
print(word[1:])
print(word[0:2])
print(word[2:])
print(word[-4:])