Python Basic Syntax
1. Print String and Integer in Python
1 2 3 4 |
print("Hello World") print('Hello World') print(""" Hello World """) print(4+5) |
2. Comment in Python
1 |
#This is a comment |
3. Create Variable in Python
1 2 3 4 5 6 |
name = 'Indocoder' print(name) length = 5 area = length * length print(area) |
4. Updating Variable
1 2 |
x = x+10 -> x+=10 x = x*10 -> x*=10 |
5. Concatenation
1 |
print('My name is'+ name) |
6. Type Conversion
1 2 3 4 5 |
age = 24 print ('My Age is '+str(age)) count = '5' print(int(count)+1) |
7. IF and ELSE Condition
1 2 3 4 5 6 7 |
score = 100 if score == 100: print('Great Job') elif score == 60: print('Not bad') else: print('You bad') |
8. True and False
1 2 |
score = 100 print(score == 100) /*Will return true*/ |
9. AND and OR expression
1 2 3 4 |
if a>10 and a<30: print('a is between 10 and 30') if not z==77: print('z is not 77') |
10. INPUT function
1 2 3 4 |
apple_price = 2 input_count = input('How many apples do you want?:') count=int(input_count) total_price = apple_price * count |
11. LISTS in Python Read more about Python Basic Syntax[…]