-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpython-syntax-sheet.txt
More file actions
111 lines (48 loc) · 1.93 KB
/
python-syntax-sheet.txt
File metadata and controls
111 lines (48 loc) · 1.93 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
# 06th march 2018 invent sekar
# python syntax learnings
#-------------------------------------
# comment - single line, multiline
#-------------------------------------
# a hash creates a single line comment
# there is no multiline comment on python. just use # on every line.
#-------------------------------------
# print
#-------------------------------------
#the correct way to print a string-
>>> print("Hello")
Hello
#is Note; however, that is Python 2.X, you could also write:
>>> print "Hello"
Hello
# ----- print blank line(s)--------
# credits - http://thomas-cokelaer.info/tutorials/python/print.html
Let us print 5 blank lines. You can naively type:
print(5 * "\n")
or:
print("\n\n\n\n\n")
or even better:
print(5 * "\n")
# ----- Print an object without a trailing newline--------
# ----- credits - http://thomas-cokelaer.info/tutorials/python/print.html
By default, the print function add a trailing line. To prevent this behavious, add a comma after the statement:
>>> x, y = 1, 2
>>> print(x),; print(y)
1 2
you could use:
print x,y,
#-------------------------------------
#user input
#-------------------------------------
# In Python 2, raw_input() returns a string, and input() tries to run the input as a Python expression.
# for Python 3.x
# The difference is that raw_input() does not exist in Python 3.x, while input() does.
# Actually, the old raw_input() has been renamed to input(), and the old input() is gone,
# but can easily be simulated by using eval(input()).
# (Remember that eval() is evil, so if try to use safer ways of parsing your input if possible.)
# from stock overflow user Sven Marnach
#-------------------------------------
#basic loops - for, while, if, else,
#-------------------------------------
#--------------------------------------------------
# Data Structures (list, dict, tuples, sets, strings)
#--------------------------------------------------