-
Notifications
You must be signed in to change notification settings - Fork 181
/
stringOperations.py
34 lines (24 loc) · 1.08 KB
/
stringOperations.py
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
# This example shows you string operations
name = 'Kalpak'
print('My name is ' + name) # I have given space after is notice
age = 14
print('My age is ', age) # comma seprates two different things you want to print
print('This isn\'t going away too soon.') # that \ is called as an escape character
# the \ is used to use same quote in a string
print('I love newlines \n') # \n prints new line after string or according to its position
print('\t I love tabs') # \t adds a tab according to its position
multiple = 'Iron Man'
print(multiple * 5) # this will print string 5 times
# string methods in built
country = 'Norway'
print(country.upper()) # prints all letters in upper case
print(country.lower()) # prints all letters in lower case
print(country.title()) # converts into title
# string formatting
print('%s %s %s'%('I' , 'am' , 'cool'))
expression = 'I love'
movie = 'Captain America 3'
print('%s %s'%(expression , movie))
# type conversion
addition = 12343 + 3349
print('The answer is ' + str(addition)) # str() method converts non-string into string