-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex22.txt
More file actions
71 lines (68 loc) · 1.89 KB
/
ex22.txt
File metadata and controls
71 lines (68 loc) · 1.89 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
THIS LIST MAY BE INCOMPLETE, I WOULD RECOMMEND THAT YOU STILL GO THROUGH ALL
THE EXERCISES MANUALLY TO SEE USAGES.
FUNCTIONS:
print()
Used to print strings. These strings can be formatted with various formatters after a % symbol.
%
Formatter for strings
%d
Formatter for integers
%r
String representation (debugging)
%s
String representation
input()
Can take a string and will return the stdin (user input)
open()
Opens the file specified and returns a file (file pointer).
'r'
Adding this to the open(file, 'r') will open the file in read mode,
this is the default mode.
'w'
This will open the file in write mode, truncating all current contents
truncate()
Truncates all the contents from the file specified
read()
Reads the entire file contents and returns it
readline()
Reads the current line of the file
seek()
Seeks the index into the file (location in file) to the index given
write()
Writes the specified string to the file at the current location
OPERATORS:
=
Assign a value to a variable
+
Addition
+=
Add value to the current variables value and store it in the variable
-
Subtractions
*
Multiplication
or allowing any number of arguments (recall *argv)
/
integer division. Example: 3/4 = 0, 5/4 = 1
//
float division. Example: 3//4 = 0.75
,
Used to seperate arguments
#
Used to start a comment
"text"
" is used to make a String
'text'
' is also used to make a String
"""text over
several lines"""
""" another way of specifying a string. Also used for giving function
descriptions.
OTHER KEYWORDS:
from
keyword used to specify the module to import something from
import
Used to specify the 'feature' to import from the module
def name():
Used to define a function called name with parameters (given arguments) in
the parenthesises ().