print(“Hello World!
”)
print(‘Hello World!’)
print(3*5)
input(“What is your name: ”)
Program Run Result
Name ------------
my_name = input(“What is your name: ”)
print(“Hello” + “ ” + my_name)
file extension (.py) / [Link]
first_num = input(“Enter your first number: ”)
second_num = input(“Enter your second number: ”)
print(“The sum of your number is: ” + first_num + second_num)
program Run Result
type 10
type 15
1015
first_num = int(input(“Enter your first number: ”))
second_num = int(input(“Enter your second number: ”))
print(“The sum of your number is: ” + str(first_num + second_num))
program Run Result
type 10
type 15
25
Python Syntax
x=5
y = “Hello World!”
print(x)
print(y)
comments
#This is a comment.
print(“Hello World!”)
print(“Hello World!”) #This is a comment.
A comment does not have to be text that explains the code, it can be used to
prevent Python from executing code:
“””
This is a comment
written in
more than just one line
“””
Python Variables for storing data values.
x=4 # x is of type of int
x = “Sally” # x is now type of str
print(x)
Run Result
Sally
Case_Sensitive
Variable names are case-sensitive
a=4
A = “Sally”
#A will not overwrite a
print(a)
print(A)
Python Data Types
Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: Bool *(represent one of “True” or “False”
Binary Types: bytes, bytearray, memoryview
None Type: NoneType
You can assign a multiline string to a variable by using three quotes:
a = """Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua."""
print(a)
Program Run Result
Lorem ipsum dolor sit amet,
consectetur adipiscing elit,
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua.
a = “I can not sleep”
b = ‘I can’t sleep’
print(a)
print(b)
print(type(a))
print(type(b))
Program Run Result
<class ‘str’>
<class ‘str’>
my_name = input(“What is your name: ”)
print(“My name is:” + “ ” + my_name)
my_age = input(“How old are you: ”)
print(“I am ” + my_age + “years old.”)
my_name = “Aung Aung”
my_age = “10 years”
print(“My name and age is: ” + my_name + “, ” + my_age)
cars = ["Ford", "Volvo", "BMW"]
print(cars)
Program Run Result
['Ford', 'Volvo', 'BMW]
cars = ["Ford", "Volvo", "BMW"]
x = cars[0]
print(x)
Program Run Result
Ford
cars = ["Ford", "Volvo", "BMW"]
cars[0] = "Toyota"
print(cars)
Program Run Result
['Toyota', 'Volvo', 'BMW]
fruits = ["apple", "banana", "cherry"]
for x in fruits:
print(x)
Program Run Result
apple
banana
cherry
for x in range(6):
print(x)
Program Run Result
0
1
2
3
4
5
cars = ["Ford", "Volvo", "BMW"]
x = len(cars)
print(x)
Program Run Result
3
cars = ["Ford", "Volvo", "BMW"]
for x in cars:
print(x)
Program Run Result
Ford
Volvo
BMW
my_name = ["Mg Mg", "Ma Ma", "Ko Ko"]
my_age = [10, 20, 30]
for i in range(len(my_name)):
print(str(my_name[i]), "is " + str(my_age[i]) + "years old")
my_name = [“Mg Mg”, “Ma Ma”, “Ko Ko”]
my_age = [10, 20, 30]
for i in range(len(my_name)):
print(str(my_name[i]), “is ” + str(my_age[i]) + “years old”)
Program Run Result
Mg Mg is 10years old
Ma Ma is 20years old
Ko Ko is 30years old
x = ["Mg Mg", "Ma Ma", "Ko Ko"]
y = ["21", "23", "25"]
for i in range(len(x)):
print(str(x[i]), "is " + str(y[i]) + "years old")
x = [“Mg Mg”, “Ma Ma”, “Ko Ko”]
y = [10, 20, 30]
for i in range(len(x)):
print(str(x[i]), “is ” + str(y[i]) + “years old”)
Program Run Result
Mg Mg is 21years old
Ma Ma is 23years old
Ko Ko is 25years old