This document contains a presentation on Python programming. It introduces Python basics like printing "Hello World", using Python as a calculator, strings and other data types, functions, classes, conditional statements like if/else, and repetition with while loops. The presentation covers Python concepts in 10 sections and includes code examples for each topic.
6. Who am I?
● Farhamg.Name
● Robocup Server 2D
● GNegar
● BadTag
● BlueWay
● UMS
● Xbuilder
● ...
7. Contents● What is Python?
● Hello world!
● RUN SCRIPTS!
● What is the object in Python?
● Python like as calculator!
● String and other types in Python!
● Function & Classes!
● Repeat the decision in Program!
● I/O files ;D
● HEEEEEEEEEEEEEEEEEEEEEELP!
8. Contents● What is Python?
● Hello world!
● RUN SCRIPTS!
● What is the object in Python?
● Python like as calculator!
● String and other types in Python!
● Function & Classes!
● Repeat the decision in Program!
● I/O files ;D
● HEEEEEEEEEEEEEEEEEEEEEELP!
15. Contents● What is Python?
● Hello world!
● RUN SCRIPTS!
● What is the object in Python?
● Python like as calculator!
● String and other types in Python!
● Function & Classes!
● Repeat the decision in Program!
● I/O files ;D
● HEEEEEEEEEEEEEEEEEEEEEELP!
21. Contents● What is Python?
● Hello world!
● RUN SCRIPTS!
● What is the object in Python?
● Python like as calculator!
● String and other types in Python!
● Function & Classes!
● Repeat the decision in Program!
● I/O files ;D
● HEEEEEEEEEEEEEEEEEEEEEELP!
35. Contents● What is Python?
● Hello world!
● RUN SCRIPTS!
● What is the object in Python?
● Python like as calculator!
● String and other types in Python!
● Function & Classes!
● Repeat the decision in Program!
● I/O files ;D
● HEEEEEEEEEEEEEEEEEEEEEELP!
44. MATH
$ python$ python
>>>>>> 0.1 + 0.20.1 + 0.2
0.300000000000000040.30000000000000004
You can check out the decimal module if you need more exact answers.
45. Contents● What is Python?
● Hello world!
● RUN SCRIPTS!
● What is the object in Python?
● Python like as calculator!
● String and other types in Python!
● Function & Classes!
● Repeat the decision in Program!
● I/O files ;D
● HEEEEEEEEEEEEEEEEEEEEEELP!
54. Contents● What is Python?
● Hello world!
● RUN SCRIPTS!
● What is the object in Python?
● Python like as calculator!
● String and other types in Python!
● Function & Classes!
● Repeat the decision in Program!
● I/O files ;D
● HEEEEEEEEEEEEEEEEEEEEEELP!
55. function
defdef add_numadd_num(x, y=1):(x, y=1):
'''Get x, y and return:'''Get x, y and return:
X + Y '''X + Y '''
returnreturn x + yx + y
>>>>>> printprint add_num(2, 3)add_num(2, 3)
55
>>>>>> printprint add_num(2)add_num(2)
33
57. function
defdef add_numadd_num(x, y):(x, y):
'''Get x, y and return:'''Get x, y and return:
X + Y '''X + Y '''
z = x + yz = x + y
returnreturn zz
>>>>>> printprint add_num(2, 3)add_num(2, 3)
55
58. def
defdef add_num(x, y):add_num(x, y):
'''Get x, y and return:'''Get x, y and return:
X + Y '''X + Y '''
z = x + yz = x + y
return zreturn z
>>> print add_num(2, 3)>>> print add_num(2, 3)
55
59. name
defdef add_numadd_num(x, y):(x, y):
'''Get x, y and return:'''Get x, y and return:
X + Y '''X + Y '''
z = x + yz = x + y
return zreturn z
>>> print add_num(2, 3)>>> print add_num(2, 3)
55
60. parameters
def add_numdef add_num(x, y)(x, y)::
'''Get x, y and return:'''Get x, y and return:
X + Y '''X + Y '''
z = x + yz = x + y
return zreturn z
>>> print add_num(2, 3)>>> print add_num(2, 3)
55
61. : + indent
def add_num(x, y)def add_num(x, y)::
--------'''Get x, y and return:'''Get x, y and return:
-------- X + Y '''X + Y '''
--------z = x + yz = x + y
--------return zreturn z
>>> print add_num(2, 3)>>> print add_num(2, 3)
55
62. documentation
def add_num(x, y):def add_num(x, y):
'''Get x, y and return:'''Get x, y and return:
X + Y '''X + Y '''
z = x + yz = x + y
return zreturn z
>>> print add_num(2, 3)>>> print add_num(2, 3)
55
63. body
def add_num(x, y):def add_num(x, y):
'''Get x, y and return:'''Get x, y and return:
X + Y '''X + Y '''
z = x + yz = x + y
return zreturn z
>>> print add_num(2, 3)>>> print add_num(2, 3)
55
64. return
def add_num(x, y):def add_num(x, y):
'''Get x, y and return:'''Get x, y and return:
X + Y '''X + Y '''
z = x + yz = x + y
returnreturn zz
>>> print add_num(2, 3)>>> print add_num(2, 3)
55
67. documentation
def add_num(x, y):def add_num(x, y):
'''Get x, y and return:'''Get x, y and return:
X + Y '''X + Y '''
z = x + yz = x + y
return zreturn z
>>>>>> helphelp(add_num)(add_num)
Help on function add_num in module __main__:Help on function add_num in module __main__:
add_num()add_num()
Get x,y and return:Get x,y and return:
X + YX + Y
(END)(END)
79. Contents● What is Python?
● Hello world!
● RUN SCRIPTS!
● What is the object in Python?
● Python like as calculator!
● String and other types in Python!
● Function & Classes!
● Repeat the decision in Program!
● I/O files ;D
● HEEEEEEEEEEEEEEEEEEEEEELP!
80. while
>>>>>>whilewhile b < 10:b < 10:
…… printprint bb
…… a, b = b, a+ba, b = b, a+b
……
11
11
22
33
55
88
81. while
>>>>>>whilewhile b < 10:b < 10:
…… print bprint b
…… a, b = b, a+ba, b = b, a+b
……
11
11
22
33
55
88
82. while
>>>while>>>while b < 10b < 10::
…… print bprint b
…… a, b = b, a+ba, b = b, a+b
……
11
11
22
33
55
88
83. while
>>>while b < 10>>>while b < 10::
……--------print bprint b
……--------a, b = b, a+ba, b = b, a+b
……
11
11
22
33
55
88
84. while
>>>while b < 10:>>>while b < 10:
…… printprint bb
…… a, b = b, a+ba, b = b, a+b
……
11
11
22
33
55
88
85. while
>>>while b < 10:>>>while b < 10:
…… print bprint b
…… a,a, b =b = b,b, a+ba+b
……
11
11
22
33
55
88
91. if-else
>>>>>>ifif b >= 10:b >= 10:
…… print 'big'print 'big'
…… elif b =< 8:elif b =< 8:
…… print 'small'print 'small'
…… else:else:
…… print '9'print '9'
92. if-else
>>>if>>>if b >= 10b >= 10::
…… print 'big'print 'big'
…… elif b =< 8:elif b =< 8:
…… print 'small'print 'small'
…… else:else:
…… print '9'print '9'
93. if-else
>>>if b >= 10>>>if b >= 10::
……--------print 'big'print 'big'
…… elif b =< 8:elif b =< 8:
……--------print 'small'print 'small'
…… else:else:
……--------print '9'print '9'
94. if-else
>>>if b >= 10:>>>if b >= 10:
…… printprint 'big''big'
…… elif b =< 8:elif b =< 8:
…… print 'small'print 'small'
…… else:else:
…… print '9'print '9'
95. if-else
>>>if b >= 10:>>>if b >= 10:
…… print 'big'print 'big'
…… elifelif b =< 8:b =< 8:
…… printprint 'small''small'
…… else:else:
…… print '9'print '9'
96. if-else
>>>if b >= 10:>>>if b >= 10:
…… print 'big'print 'big'
…… elifelif b =< 8:b =< 8:
…… print 'small'print 'small'
…… else:else:
…… print '9'print '9'
97. if-else
>>>if b >= 10:>>>if b >= 10:
…… print 'big'print 'big'
…… elifelif b =< 8b =< 8::
…… print 'small'print 'small'
…… else:else:
…… print '9'print '9'
98. if-else
>>>if b >= 10:>>>if b >= 10:
…… print 'big'print 'big'
…… elif b =< 8:elif b =< 8:
…… printprint 'small''small'
…… else:else:
…… print '9'print '9'
99. if-else
>>>if b >= 10:>>>if b >= 10:
…… print 'big'print 'big'
…… elif b =< 8:elif b =< 8:
…… print 'small'print 'small'
…… elseelse::
…… printprint '9''9'
100. if-else
>>>if b >= 10:>>>if b >= 10:
…… print 'big'print 'big'
…… elif b =< 8:elif b =< 8:
…… print 'small'print 'small'
…… elseelse::
…… print '9'print '9'
101. for
>>>>>> forfor nn inin [2, 3, 4, 5, 6, 7, 8, 9]:[2, 3, 4, 5, 6, 7, 8, 9]:
…… forfor xx inin rangerange(2, n):(2, n):
…… ifif n % x == 0:n % x == 0:
...... printprint nn
...... breakbreak
...... elseelse::
...... printprint n,n, 'is a prime''is a prime'
102. for
>>>>>> forfor n in [2, 3, 4, 5, 6, 7, 8, 9]:n in [2, 3, 4, 5, 6, 7, 8, 9]:
…… for x in range(2, n):for x in range(2, n):
…… if n % x == 0:if n % x == 0:
...... print nprint n
...... breakbreak
...... else:else:
...... print n, 'is a prime'print n, 'is a prime'
103. for
>>> for>>> for nn in [2, 3, 4, 5, 6, 7, 8, 9]:in [2, 3, 4, 5, 6, 7, 8, 9]:
…… for x in range(2, n):for x in range(2, n):
…… if n % x == 0:if n % x == 0:
...... print nprint n
...... breakbreak
...... else:else:
...... print n, 'is a prime'print n, 'is a prime'
104. for
>>> for n>>> for n inin [2, 3, 4, 5, 6, 7, 8, 9]:[2, 3, 4, 5, 6, 7, 8, 9]:
…… for x in range(2, n):for x in range(2, n):
…… if n % x == 0:if n % x == 0:
...... print nprint n
...... breakbreak
...... else:else:
...... print n, 'is a prime'print n, 'is a prime'
105. for
>>> for n in>>> for n in [2, 3, 4, 5, 6, 7, 8, 9][2, 3, 4, 5, 6, 7, 8, 9]::
…… for x in range(2, n):for x in range(2, n):
…… if n % x == 0:if n % x == 0:
...... print nprint n
...... breakbreak
...... else:else:
...... print n, 'is a prime'print n, 'is a prime'
106. for
>>> for n in [2, 3, 4, 5, 6, 7, 8, 9]:>>> for n in [2, 3, 4, 5, 6, 7, 8, 9]:
…… forfor xx inin rangerange(2, n):(2, n):
…… ifif n % x == 0:n % x == 0:
...... printprint nn
...... breakbreak
...... elseelse::
...... printprint n,n, 'is a prime''is a prime'
107. for
>>> for n in [2, 3, 4, 5, 6, 7, 8, 9]:>>> for n in [2, 3, 4, 5, 6, 7, 8, 9]:
…… for x infor x in rangerange(2, n)(2, n)::
…… if n % x == 0:if n % x == 0:
...... print nprint n
...... breakbreak
...... else:else:
...... print n, 'is a prime'print n, 'is a prime'
108. for
>>> for n in [2, 3, 4, 5, 6, 7, 8, 9]:>>> for n in [2, 3, 4, 5, 6, 7, 8, 9]:
…… for x in range(2, n):for x in range(2, n):
…… if n % x == 0:if n % x == 0:
...... print nprint n
...... breakbreak
...... else:else:
...... print n, 'is a prime'print n, 'is a prime'
109. for
>>>>>> dict = {dict = { 'a''a':1 ,:1 , 'b''b'::'AB''AB',, 'c''c':[1,{}] }:[1,{}] }
>>>>>>forfor key, valkey, val inin dict.items()dict.items()::
…… printprint key, valkey, val
a 1a 1
b ABb AB
c [1,{}]c [1,{}]
110. Contents● What is Python?
● Hello world!
● RUN SCRIPTS!
● What is the object in Python?
● Python like as calculator!
● String and other types in Python!
● Function & Classes!
● Repeat the decision in Program!
● I/O files ;D
● HEEEEEEEEEEEEEEEEEEEEEELP!
120. Contents● What is Python?
● Hello world!
● RUN SCRIPTS!
● What is the object in Python?
● Python like as calculator!
● String and other types in Python!
● Function & Classes!
● Repeat the decision in Program!
● I/O files ;D
● HEEEEEEEEEEEEEEEEEEEEEELP!
124. trace
●● h - helph - help
●● s - step intos - step into
●● n - nextn - next
●● c - continuec - continue
●● w - where am I (in stack)?w - where am I (in stack)?
●● l - list code around mel - list code around me
125. trace
hh - help- help
ss - step into- step into
nn - next- next
cc - continue- continue
ww - where am I (in stack)?- where am I (in stack)?
ll - list code around me- list code around me