Code examples-simple

Is this a valid python statement ?

birth_year = input('birth year: ')
age = 2019 - birth_year
print(age)

Ans: no

correct is:

birth_year = input('birth year: ')
age = 2019 - int(birth_year)
print(age)
====
Whats the output for:

hobby = 'Eat biryani and sleep well'
print(hobby.upper())

output: EAT BIRYANI AND SLEEP WELL

Note: raw_input is being used in Python 2. In Python 3 creators replaced that with just input.

====
Whats the output:

Quiz:
hobby = 'Eat biryani and sleep well'
print(hobby.replace('sleep well', 'learn python')

output:

Eat biryani and learn python


Comments

Popular posts from this blog

Python libraries and their uses

Python tutorial video -6 hours of detailed step by step tutorial by Mosh

PyCharm and Jupyter Notebook compared