Virables
name = 'John'
age = 22
height = 170.9
print(name)
print(age)
print(height)
String Methods
string = 'Absolutely-beautiful-string'
print(len(string))
print(string.find('bea'))
print(string.capitalize())
print(string.upper())
print(string.lower())
print(string.isdigit())
print(string.isalpha())
print(string.count('b'))
print(string.replace('e', 'u'))
print((string + ' ') *5)
Type Cast
integer = 22
string = 'John'
float = 174.85
integer = str(integer)
float = str(float)
print(string + ' is ' + integer + ' years old and ' + float + ' cm high.')
User input
name = input('What is your name?')
city = input('Whare are you from?')
temp = float(input('How is the weather here?'))
print('Hello, ' + name + '. You are from ' + city + ', where the weather is ' + str(temp) + ' degrees')
0 Comments