Contenu connexe Similaire à Python for High School Programmers Similaire à Python for High School Programmers (20) Plus de Siva Arunachalam (18) Python for High School Programmers2. It’s me!
• Application Developer
• Web/Enterprise/Middleware/B2B
• Java/Java EE, Python/Django
• 2002
• Technical Consultant
• Process Mentor
• Speaker
4. Agenda
• Background
• Concepts
• Basics
• Demo
12. Zen of Python
• Beautiful is better than ugly.
• Explicit is better than implicit.
• Simple is better than complex.
• Complex is better than complicated.
• Flat is better than nested.
• Sparse is better than dense.
• Readability counts.
• Special cases aren't special enough to break the rules.
• Although practicality beats purity.
• Errors should never pass silently.
• Unless explicitly silenced.
• In the face of ambiguity, refuse the temptation to guess.
• There should be one-- and preferably only one --obvious way to do it.
• Although that way may not be obvious at first unless you're Dutch.
• Now is better than never.
• Although never is often better than *right* now.
• If the implementation is hard to explain, it's a bad idea.
• If the implementation is easy to explain, it may be a good idea.
• Namespaces are one honking great idea -- let's do more of those!
16. Portable
• Servers / Desktops / Mobile Devices / Raspberry Pi
• Windows/Unix/Linux/Mac
• Pre-installed in Mac and Linux
25. Where I can use?
• Stand-Alone Application
• Desktop/GUI Application
• Web Application
• XML Processing
• Database Application
• Network Application
• Scientific Application
• Gaming
• Robotics
38. Let’s Start
• Start / Exit
• Simple print
• Zen of Python
• Keywords
• Help
41. int_ex = 10
long_ex = 1000000000000L
float_ex = 1.1
string_ex = “Welcome”
boolean_ex = True
43. print type(int_ex)
print type(long_ex)
print type(float_ex)
print type(string_ex)
print type(boolean_ex)
44. boolean_one = True
boolean_two = False
print boolean_one and boolean_two
print boolean_one or boolean_two
print not boolean_two
45. int_one = 11
int_two = 5
print int_one / int_two
print float(int_one) / float(int_two)
print float(int_one) / int_two
print int_one / float(int_two)
47. int_ex = 11
float_ex = 8.8
boolean_ex = True
print float (int_ex)
print int (float_ex)
print int (boolean_ex)
48. int_one = 11
int_two = 5
print int_one + int_two
print int_one - int_two
print int_one * int_two
print int_one / int_two
print int_one % int_two
print int_one ** int_two
49. int_one = 11
int_two = 5
print int_one > int_two
print int_one >= int_two
print int_one < int_two
print int_one <= int_two
print int_one == int_two
print int_one != int_two
53. int_one = 11
int_two = 5
import math
print math.sqrt (int_one)
import math
from math import factorial
print math.pi
print factorial (int_two)
57. int_one = raw_input (“Number 1 : “)
int_two = raw_input (“Number 2 : “)
print int_one + int_two
print int(int_one) + int(int_two)
60. ‘ ’
“ ”
“““ ”””
‘‘‘ ’’’
61. print ‘ example text ’
print “ example text ”
print “““ example of long …..
…. text ”””
print ‘‘‘ example of long …..
…. text ’’’
62. print ‘ String with “double” quotes ’
print “String with ‘single’ quote ”
print ““ Hey what‘s up””
print ‘“ Hey what‘s up”’
print “““ “ Hey what‘s up ” ”””
print ‘‘‘ “ Hey what‘s up ” ’’’
65. 0 1 2 3 4 5
10 10.1 ‘A’ ‘ABC’ 2 True
-6 -5 -4 -3 -2 -1
66. 0 1 2 3 4 5
10 10.1 ‘A’ ‘ABC’ 2 True
-6 -5 -4 -3 -2 -1
list_ex = [ 10, 10.1, ‘A’, ‘ABC’, 2, True ]
tuple_ex = ( 10, 10.1, ‘A’, ‘ABC’, 2, True )
68. 0 1 2 3 4 5
10 10.1 ‘A’ ‘ABC’ 2 True
-6 -5 -4 -3 -2 -1
tuple_ex = ( 10, 10.1, ‘A’, ‘ABC’, 2, True )
• tuple_ex[0] • tuple_ex[-6]
• tuple_ex[1] • tuple_ex[-5]
• tuple_ex[2] • tuple_ex[-4]
• tuple_ex[3] • tuple_ex[-3]
• tuple_ex[4] • tuple_ex[-2]
• tuple_ex[5] • tuple_ex[-1]
70. tuple_ex = (100, )
list_ex = [100, ]
tuple_ex = tuple(‘gobi’)
list_ex = list(‘gobi’)
72. 0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1
list_ex = [1, 2, 3, 4, 5, 6, 7, 8, 9 , 10, ]
print list_ex[:3]
print list_ex[3:]
print list_ex[:-3]
print list_ex[-3:]
73. 0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1
list_ex = [1, 2, 3, 4, 5, 6, 7, 8, 9 , 10, ]
print list_ex[0:1]
print list_ex[0:2]
print list_ex[-2:-1]
print list_ex[-3:-1]
74. 0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1
list_ex = [1, 2, 3, 4, 5, 6, 7, 8, 9 , 10, ]
print list_ex[0:10:2]
print list_ex[1:10:2]
75. 0 1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8 9 10
-10 -9 -8 -7 -6 -5 -4 -3 -2 -1
list_ex = [1, 2, 3, 4, 5, 6, 7, 8, 9 , 10, ]
print len(list_ex)
print max(list_ex)
print min(list_ex)
77. city = list(‘gobi’)
city[len(city):] = “chettipalayam”
“”.join(city)
78. ipl_teams = [‘CSK’, ‘DD’, ‘KXIP’, ‘KKR’, ‘MI’, ‘PWI’, ‘RR’, ‘RCB’, ‘SRH’,]
“, ”.join(ipl_teams)
79. str_ipl_teams = “, ”.join(ipl_teams)
list_ipl_teams = list(str_ipl_teams )
list_ipl_teams[str_ipl_teams.rfind(", ")] = " and“
print "".join(list_ipl_teams)
80. ipl_teams = [‘CSK’, ‘DD’, ‘KXIP’, ‘KKR’, ‘MI’, ‘PWI’, ‘RR’, ‘RCB’,]
ipl_teams.append(‘SRH’)
81. ipl_teams = [‘CSK’, ‘DD’, ‘KXIP’, ‘KKR’, ‘MI’, ‘PWI’, ‘RR’, ‘RCB’,]
ipl_teams.remove(‘SRH’)
del ipl_teams[-1]
82. ipl_teams = [‘CSK’, ‘DD’, ‘KXIP’, ‘KKR’, ‘MI’, ‘PWI’, ‘RR’, ‘RCB’,]
ipl_teams.insert (1, ‘SRH’)
83. ipl_teams = [‘CSK’, ‘SRH’, ‘DD’, ‘KXIP’, ‘KKR’, ‘MI’, ‘PWI’, ‘RR’, ‘RCB’,]
ipl_teams.sort()
93. for i in range(11):
if i % 2 == 0:
print i
94. for i in range(11):
if i % 2 == 0:
print “Even : ”, i
else :
print “Odd: ”, i
95. for i in range(11):
if i == 0:
pass
elif i % 2 == 0:
print “Even : ”, i
else :
print “Odd: ”, i
96. for i in range(11):
if i == 0:
continue
elif i % 2 == 0:
print “Even : ”, i
else :
print “Odd: ”, i
97. for i in range(11):
if i == 0:
break
elif i % 2 == 0:
print “Even : ”, i
else :
print “Odd: ”, i
99. for i in range(11):
print i,
else:
print “No Break executed in for”
101. list_ex = []
if list_ex:
print “List is not Empty”
else:
print “List is Empty”
105. Thank You!
siva@sivaa.in
bit.ly/sivaa_in bit.ly/sivasubramaniam