-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonPracticeCodeConsole.py
More file actions
152 lines (151 loc) · 2.59 KB
/
PythonPracticeCodeConsole.py
File metadata and controls
152 lines (151 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> 3 + 4
7
>>> 3 - 12
-9
>>> 3 * 4
12
>>> 12 / 4
3.0
>>> 12 / 5
2.4
>>> 12//5
2
>>> 8 + 2 * 10
28
>>> (8 + 2) * 10
100
>>> 18 /3
6.0
>>> 18 % 4
2
>>> 18 / 4
4.5
>>> 5 * 5 * 5
125
>>> 5 ** 3
125
>>> t = 5
>>> a = 4
>>> t + a
9
>>> 'kp'
'kp'
>>> "kp"
'kp'
>>> kp
Traceback (most recent call last):
File "<pyshell#18>", line 1, in <module>
kp
NameError: name 'kp' is not defined
>>> 'I don't think so'
SyntaxError: invalid syntax
>>> " I don't think so"
" I don't think so"
>>> 'she said " I don't think so"'
SyntaxError: invalid syntax
>>> 'she said " I think so" '
'she said " I think so" '
>>> she said " I think so "
SyntaxError: invalid syntax
>>> 'I don\'t think so'
"I don't think so"
>>> " I don't think so"
" I don't think so"
>>> 'I don't think so "
SyntaxError: invalid syntax
>>> print("Hi")
Hi
>>> print ('C:\pictures')
C:\pictures
>>> print ('c:\pictures\noon')
c:\pictures
oon
>>> print (r'c:\pictures\noon')
c:\pictures\noon
>>> firstName = "kp"
>>> firstName + "pj"
'kppj'
>>> firstname + " pj "
Traceback (most recent call last):
File "<pyshell#33>", line 1, in <module>
firstname + " pj "
NameError: name 'firstname' is not defined
>>> firstname = "kp"
>>> firstname + " pj "
'kp pj '
>>> firstname = "kp"
>>> firstname * 5
'kpkpkpkpkp'
>>> user = "kp pj"
>>> user[0]
'k'
>>> user[3]
'p'
>>> user[-1]
'j'
>>> user[-3]
' '
>>> user[3]
'p'
>>> user[-6]
Traceback (most recent call last):
File "<pyshell#44>", line 1, in <module>
user[-6]
IndexError: string index out of range
>>> user[-5]
'k'
>>> user[1]
'p'
>>> user[1:5]
'p pj'
>>> user[:5]
'kp pj'
>>> user[3:]
'pj'
>>> user[:]
'kp pj'
>>> len('user')
4
>>> len("user")
4
>>> len(user)
5
>>> players = [12,13,15,18,39,45]
>>> players[4]
39
>>> players[0]
12
>>> players[2]
15
>>> players[2] = 68
>>> players
[12, 13, 68, 18, 39, 45]
>>> players + [3,8,9]
[12, 13, 68, 18, 39, 45, 3, 8, 9]
>>> players
[12, 13, 68, 18, 39, 45]
>>> players + append(3,8,9)
Traceback (most recent call last):
File "<pyshell#62>", line 1, in <module>
players + append(3,8,9)
NameError: name 'append' is not defined
>>> players.append(3,8,9)
Traceback (most recent call last):
File "<pyshell#63>", line 1, in <module>
players.append(3,8,9)
TypeError: append() takes exactly one argument (3 given)
>>> players.append(120)
>>> players
[12, 13, 68, 18, 39, 45, 120]
>>> players[:2]
[12, 13]
>>> players[:2] = [0,0]
>>> players
[0, 0, 68, 18, 39, 45, 120]
>>> players[:2] = []
>>> players[:] = []
>>> players
[]
>>>