Basic_Python_2
Basic_Python_2
Python
Operation,
List &
Condition
Page 01
Content
Example:
name = input("Enter name:")
print("Your name is: " + name)
Page 03
Python: String Operations
Get the character at position 1 (the first character has the position 0)
a = "Hello, World!"
print(a[1])
Page 04
Python: String Operations
Page 05
Python: String Formatting
The format() method takes the passed arguments, formats them, and
places them in the string where the placeholders {} are:
age = 36
txt = "My name is John, and I am {}".format(age)
print(txt)
Page 06
Quiz Session
Page 07
Quiz
if x = "Indonesia AI"
❖ print(x[2:4])
❖ print(len(x))
Page 08
Python: Booleans
Example:
print(10 > 9)
print(10 == 9)
print(10 < 9)
a = 10
b=9
if b > a:
print("b is greater than a")
else:
print("b is not greater than a")
Page 09
Python: List
They can contain any type of variable, and they can contain as many variables as you
wish. Lists can also be iterated over in a very simple manner. Here is an example of how
to build a list. For example:
mylist = []
mylist.append(1)
mylist.append(2)
mylist.append(3)
print(mylist[0]) # prints 1
print(mylist[1]) # prints 2
print(mylist[2]) # prints 3
Page 10
Python: Conditions (If...Else)
a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
Page 11
Quiz Session
Page 12
Quiz
c=3
a=c
b=c+1
if b > a:
print("b is greater than a")
elif c == b:
print("c is same like b")
else :
print('other')
Page 13
Terima Kasih!
Indonesia AI | AI for Everyone, AI for Indonesia
contact@aiforindonesia.org