1
1
# The Beginning
2
2
3
- ## Using Python interpreter
3
+ ## [ Using Python interpreter] ( https://docs.python.org/3/tutorial/interpreter.html )
4
4
5
- * Type ' python3' command in terminal to open python interpreter
5
+ * Type ` python3 ` command in terminal to open a Python Interpreter.
6
6
7
7
```
8
8
[raukadah@ironman python-workshop]$ python3
@@ -11,44 +11,47 @@ Python 3.7.3 (default, Mar 27 2019, 13:36:35)
11
11
Type "help", "copyright", "credits" or "license" for more information.
12
12
>>>
13
13
```
14
- * * >>>* knowns as python prompt
15
- * Use CTRL + D to exit from the terminal
14
+ * ` >>> ` is known as python prompt.
15
+ * Use ` CTRL + d ` to exit from the terminal or ` exit() ` command.
16
16
* After quitting, all programs will get destroyed.
17
17
18
18
## My first program
19
- * * print()* method is used to display output to the use
19
+ * ` print() ` method is used to display output like ` printf ` in * C language* .
20
+
20
21
```
21
22
>>> print('Welcome to FOSSMEET, PUNE')
22
23
Welcome to FOSSMEET, PUNE
23
24
```
24
25
25
- * We can also print in multiple lines by using * \n * .
26
+ * We can also print in multiple lines by using ` \n ` .
26
27
```
27
28
>>> print('Welcome to FOSSMEET, PUNE\n Let\'s Learn Python 3')
28
29
Welcome to FOSSMEET, PUNE
29
30
Let's Learn Python 3
30
31
```
31
32
We can * \* to escape any characters.
32
33
33
- ## Use * #* to comment the code
34
- Anything written afer * # * will be ignored.
34
+ ## [ Use * #* to comment the code] ( https://www.python.org/dev/peps/pep-0008/#comments )
35
+ Anything written after ` # ` will be ignored.
35
36
```
36
37
>>> # print('This is a comment')
37
38
...
38
39
>>>
39
40
```
40
41
41
42
## Variables
42
- * Variables in Python allows us to store information and give it a label
43
- we can use to retrieve that information later.
43
+ * Variables in Python allows us to store information and give it a label.
44
+ We can use to retrieve that information later.
45
+
46
+ * We can store numbers, strings (* a sequence of characters* ) and complex data
47
+ types.
44
48
45
- * We can store numbers, strings (a squenece of characters) and complex data
46
- types
47
49
* We assign values to variables by putting the value to the right of an equal
48
50
sign.
49
- * Since Python is a dynamic language so we donot need to define the data type of
50
- a variable.
51
- * Let's define a varibale.
51
+
52
+ * Python is a [ General purpose programming language] ( https://en.wikipedia.org/wiki/General-purpose_programming_language ) .
53
+
54
+ * Let's define a variable.
52
55
```
53
56
>>> a = 12 # *a* is a variable holding the value 2
54
57
>>> b = 'Hello' # *b* is another variable holding string
@@ -58,9 +61,9 @@ Anything written afer *#* will be ignored.
58
61
'Hello'
59
62
>>>
60
63
```
61
- * variable can be called any times based on needs.
64
+ * Variable can be called any times based on needs.
62
65
63
- ## String representation
66
+ ## [ String representation] ( https://docs.python.org/3/tutorial/introduction.html#strings )
64
67
* We can represent string using single, double or triple quotes.
65
68
```
66
69
>>> a = 'Hello World'
@@ -79,18 +82,18 @@ Anything written afer *#* will be ignored.
79
82
80
83
It is a multi line string
81
84
Have fun, when we print it
82
-
83
85
>>>
84
86
```
85
- * We can * print* method to display the output.
87
+ * We can ` print ` method to display the output.
86
88
87
- ## Whitespaces and Identation
88
- * We gives whitespaces between operators to make code more readable.
89
+ ## [ Whitespaces and Indentation ] ( https://docs.python.org/2.0/ref/indentation.html )
90
+ * We give whitespaces between operators to make the code more readable.
89
91
* Space at the beginning of a line is known as indentation.
90
- * On using wrong indentation, it will give indentation error
92
+ * On using the wrong indentation, it will give indentation error
91
93
* Let's see
92
94
```
93
95
>>> a = 'foobar'
96
+
94
97
>>> a = 'foobar'
95
98
File "<stdin>", line 1
96
99
a = 'foobar'
@@ -100,7 +103,7 @@ IndentationError: unexpected indent
100
103
```
101
104
102
105
## Variable Naming
103
- * Name of the variable should be meaningfull .
106
+ * Name of the variable should be meaningful .
104
107
* We generally use Number, Characters and underscore for naming
105
108
variables.
106
109
* On using special characters it will through error.
@@ -114,7 +117,7 @@ IndentationError: unexpected indent
114
117
^
115
118
SyntaxError: invalid syntax
116
119
```
117
- * Python provides a list of keywords which cannot be used a variable name.
120
+ * Python provides a list of ` keywords ` which can't be used a variable name.
118
121
119
122
## Multiple assignment in a single line
120
123
We can even assign multiple values in a single line.
@@ -148,13 +151,13 @@ We can even assign multiple values in a single line.
148
151
>>> (10 * 20 / 2 -100 ) + 50 # We can call it as a expression
149
152
50.0
150
153
```
151
- * * +, -, * , / * are used for addition, substraction, multiplication and
154
+ * ` + ` , ` - ` , ` * ` , ` / ` are used for addition, substraction, multiplication and
152
155
division.
153
- * ' ** ' for calculating powers
154
- * '/' returns floating point numbers
155
- * '//' is used to discard fractional part.
156
- * We can also try BODMAS rule in a expression
157
- * These are known as arithmetic operators
156
+ * ` ** ` for calculating powers.
157
+ * ` / ` returns floating point numbers.
158
+ * ` // ` is used to discard fractional part.
159
+ * We can also try ` BODMAS ` rule in an expression.
160
+ * These are known as arithmetic operators.
158
161
159
162
## Relational Operators
160
163
```
@@ -172,10 +175,10 @@ True
172
175
True
173
176
```
174
177
175
- ## Logical operator
176
- * * and* and * or * are logical operator
177
- * x and y returns False if x is False else it returns evaluation of y .
178
- If x is True, it returns True.
178
+ ## Logical Operator
179
+ * ` and ` and ` or ` are a logical operator.
180
+ * ` x ` and ` y ` returns ` False ` if ` x ` is ` False ` else it returns evaluation of ` y ` .
181
+ If ` x ` is ` True ` , it returns ` True ` .
179
182
```
180
183
>>> 1 and 4
181
184
4
189
192
0
190
193
```
191
194
192
- ## Shorthand operator
193
- * * x op = expression* is the syntax for shorthand operators.
195
+ ## Shorthand Operator
196
+ * ` x operator = expression` is the syntax for shorthand operators.
194
197
```
195
198
>>> a = 15
196
199
>>> b += 30
199
202
```
200
203
201
204
## Taking input from keyword
202
- * * input()* method is used to take input from keyboard
205
+ * ` input() ` method is used to take ` input ` from ` keyboard ` .
203
206
```
204
207
>>> input("Enter your name: ")
205
208
Enter your name: Chandan Kumar
@@ -210,9 +213,9 @@ Enter your name: raukadah
210
213
'raukadah'
211
214
>>>
212
215
```
213
- ## type conversion
214
- * we can use * type()* to check the data type of a variable
215
- * we can also convert it
216
+ ## Type conversion
217
+ * We can use ` type() ` to check the data type of a variable.
218
+ * We can also convert it.
216
219
```
217
220
>>> a = 10
218
221
>>> c = 1.5
@@ -256,30 +259,29 @@ TypeError: cannot concatenate 'str' and 'int' objects
256
259
```
257
260
258
261
## Writting a program in file
259
- * All programs are written with * <filename >.py*
260
- * Open a file named * first_program.py* and write the following
261
- code.
262
+ * All programs are written with ` <filename>.py ` .
263
+ * Create a file named ` first_program.py ` and write the following code.
262
264
```
263
265
#!/usr/bin/env python3
264
266
265
267
myname = input("Enter your name: ")
266
268
print('Welcome to Python3 Fun Class %s' % myname)
267
269
```
268
- * Make the program executable
270
+ * Make the program executable.
269
271
```
270
272
$ chomd +x first_program.py
271
273
```
272
- * Then run it
274
+ * Then run it.
273
275
```
274
276
$./first_program.py
275
277
```
276
- * On the first line you can #! , what we call it sha-bang.
277
- The sha-bang indicates that the Python interpreter should run this code.
278
+ * On the first line you can ` #! ` , what we call it [ sha-bang] ( https://en.wikipedia.org/wiki/Shebang_(Unix) .
279
+ The ` sha-bang ` indicates that the Python interpreter should run this code.
278
280
279
- ## Decision Making using if,else
280
- While working on programs, we always encounted with making decisions.
281
- Based on condition, we need to perform tasks or do other tasks.
282
- We can * if * keyword to that.
281
+ ## Decision Making using if, else
282
+ While working on programs, we always encounter with making decisions.
283
+ Based on the condition, we need to perform tasks or do other tasks.
284
+ We can use ` if ` keyword to that.
283
285
```
284
286
if expression:
285
287
do
@@ -310,18 +312,18 @@ if a:
310
312
```
311
313
312
314
## Functions
313
- * When we have to do a certain set of operatin multiple times and reuse it
314
- with in codebase then we need to define a function
315
- * * def* keyword is used to define a function
316
- * syntex
315
+ * When we have to do a certain set of operation multiple times and reuse it
316
+ with in codebase then we need to define a function.
317
+ * ` def ` keyword is used to define a function.
318
+ * Syntax:
317
319
```
318
320
def function_name(function_arguments):
319
321
do some stuff
320
322
return something
321
323
```
322
324
* Here function_arguments are not necessary.
323
325
* function arguments can be passed in any fashion
324
- * if return is not define, it will not return anything.
326
+ * If return is not define, it will not return anything (None) .
325
327
```
326
328
>>> def sum(a, b):
327
329
... print(a + b)
@@ -356,13 +358,13 @@ None
356
358
```
357
359
358
360
### For loop
359
- In python loop works over sequence .
360
- Sequence might be a list, string, tuples or dictionary.
361
+ In Python loop works over a ` Iterator ` object .
362
+ might be a ` list ` , ` string ` , ` tuples ` , ` dictionary ` , ` set ` etc .
361
363
```
362
364
for i in sequence:
363
365
do some stuff
364
366
```
365
- Let's print the letter of a word.
367
+ Let's ` print ` the letter of a word.
366
368
```
367
369
>>> word = "fossmeet"
368
370
>>> for i in word:
@@ -372,11 +374,11 @@ f*o*s*s*m*e*e*t*
372
374
```
373
375
374
376
### Looping over integers
375
- * Use range() function
376
- * range() can be used in three ways
377
- * range(n): will contain numbers form 0 through n-1
378
- * range(x, y): will start from x and end at y - 1
379
- * range(x, y, z): will start at x and continue as x + z, x + 2z until x + kz is less than y
377
+ * Use ` range() ` function.
378
+ * ` range() ` can be used in three ways.
379
+ * ` range(n) ` : will contain numbers form ` 0 ` through ` n-1 `
380
+ * ` range(x, y) ` : will start from ` x ` and end at ` y-1 `
381
+ * ` range(x, y, z) ` : will start at ` x ` and continue as ` x+z ` , ` x+2z ` until ` x+kz ` is less than ` y ` .
380
382
```
381
383
>>> range(10)
382
384
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
@@ -400,5 +402,3 @@ f*o*s*s*m*e*e*t*
400
402
8 square is 64
401
403
9 square is 81
402
404
```
403
-
404
- ## Time to learn some more stuff
0 commit comments