You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: python/04-loops.md
+4-4
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
<h1align="center"> LOOPS </h1>
2
2
3
3
## Why LOOPS?
4
-
* Loops make our life easier by making it easier for us to perform repetetive task without having to actually write the same piece of code again and again that many times
4
+
* Loops make our life easier by making it easier for us to perform repetitive task without having to actually write the same piece of code again and again that many times
5
5
6
6
* That is it helps you to perform a task as many as times you require depending on the condition you specify
7
7
@@ -18,7 +18,7 @@
18
18
19
19
```python
20
20
count=1# initializes a counter variable equal to 1
21
-
while(count<=10): # checks if value of counter is less than equal to 15 if yes then execute the below
21
+
while(count<=10): # checks if value of counter is less than equal to 10 if yes then execute the below
22
22
print(str(count)+") I will do my homework everyday")
23
23
count=count+1#increments the value of counter otherwise it will remain less than 10 forever and thus infinite loop
24
24
print("Sorry")
@@ -52,7 +52,7 @@ Here one should take care of the fact that lines which are indented inside the w
52
52
list=['Jofrey','Cersei','Walder Frey','Meryn Trant','The Red Woman','Beric Dondarrion','Thoros of Myr','Ilyn Payne','The Mountain','The Hound'] # initialize a list with some values
53
53
for people inlist: # assigns people a temporary value of elements in the list one by one and executes the code till all elemets in the list are iterated
54
54
print(people) #prints the current value in the variable people each time
55
-
print("-Arya Stark") # You know who is it but look out for the indentation
55
+
print("-Arya Stark") # You know who it is but look out for the indentation
56
56
```
57
57
_Output_
58
58
```
@@ -72,7 +72,7 @@ The Hound
72
72
73
73
### Implementation
74
74
```python
75
-
for x inrange(1,11): #make a note of of the ending point of the list
75
+
for x inrange(1,11): #make a note of the ending point of the list
76
76
print(x,"Mississippi") # x takes one by one each value in the range
Copy file name to clipboardExpand all lines: python/05-Strings.md
+11-11
Original file line number
Diff line number
Diff line change
@@ -2,11 +2,13 @@
2
2
3
3
<h2>Introduction</h2>
4
4
5
-
>Python has a built-in string class named "str" with many handy features (there is an older module named "string" which you should not use). Python strings are "immutable" which means they cannot be changed after they are created. Since strings can't be changed, we construct *new* strings as we go to represent computed values. So, for example the expression ('hello' + 'there') takes in the 2 strings 'hello' and 'there' and builds a new string 'hellothere'.</br>
5
+
>Python has a built-in string class named "str" with many handy features (there is an older module named "string" which you should not use). Python strings are "immutable" which means they cannot be changed after they are created. Since strings can't be changed, we construct *new* strings as we go to represent computed values.
6
6
7
-
>Characters in a string can be accessed using the standard [] syntax. Python uses zero-based indexing, so if str is 'hello' str[1] is 'e'. If the index is out of bounds for the string, Python raises an error. The Python style (unlike Perl) is to halt if it can't tell what to do, rather than just make up a default value. The handy "slice" syntax (below) also works to extract any substring from a string. The len(string) function returns the length of a string. The [] syntax and the len() function actually work on any sequence type -- strings, lists, etc. Python tries to make its operations work consistently across different types. The '+' operator can concatenate two strings.</br>
7
+
>So, for example the expression ('hello' + 'there') takes in the 2 strings 'hello' and 'there' and builds a new string 'hellothere'.
8
8
9
-
>Notice in the code below that variables are not pre-declared -- just assign to them and go.</br>
9
+
>Characters in a string can be accessed using the standard [] syntax. Python uses zero-based indexing, so if str is 'hello' str[1] is 'e'. If the index is out of bounds for the string, Python raises an error. The handy "slice" syntax (below) also works to extract any substring from a string. The len(string) function returns the length of a string. The [] syntax and the len() function actually work on any sequence type -- strings, lists, etc. Python tries to make its operations work consistently across different types. The '+' operator can concatenate two strings.
10
+
11
+
>Notice in the code below that variables are not pre-declared -- just assign to them and go.
10
12
11
13
_**Example**_
12
14
```python
@@ -16,7 +18,7 @@ print len(s) ## 2
16
18
print s +' there'## hi there
17
19
```
18
20
19
-
>The str() function converts values to a string form so they can be combined with other strings.</br>
21
+
>The str() function converts values to a string form so they can be combined with other strings.
20
22
21
23
_**Example**_
22
24
```python
@@ -25,11 +27,9 @@ pi = 3.14
25
27
text ='The value of pi is '+str(pi) ## yes
26
28
```
27
29
28
-
>For numbers, the standard operators, +, /, * work in the usual way. There is no ++ operator, but +=, -=, etc. work. If you want integer division, it is most correct to use 2 slashes -- e.g. 6 // 5 is 1 (previous to python 3000, a single / does int division with ints anyway, but moving forward // is the preferred way to indicate that you want int division.)</br>
29
-
30
30
<h2>String Methods</h2>
31
31
32
-
>Here are some of the most common string methods. A method is like a function, but it runs "on" an object.</br>
32
+
>Here are some of the most common string methods. A method is like a function, but it runs "on" an object.
33
33
34
34
<h2>Functions</h2>
35
35
@@ -48,7 +48,7 @@ text = 'The value of pi is ' + str(pi) ## yes
48
48
49
49
<h2>String Slices</h2>
50
50
51
-
>The "slice" syntax is a handy way to refer to sub-parts of sequences -- typically strings and lists. The slice s[start:end] is the elements beginning at start and extending up to but not including end. Suppose we have s = "Hello"</br>
51
+
>The "slice" syntax is a handy way to refer to sub-parts of sequences -- typically strings and lists. The slice s[start:end] is the elements beginning at start and extending up to but not including end. Suppose we have s = "Hello"
52
52
53
53
| <center>Function </center> | <center>What it does</center>
54
54
| :------------- | :-------------
@@ -59,7 +59,7 @@ text = 'The value of pi is ' + str(pi) ## yes
59
59
60
60
61
61
62
-
>The standard zero-based index numbers give easy access to chars near the start of the string. As an alternative, Python uses negative numbers to give easy access to the chars at the end of the string: s[-1] is the last char 'o', s[-2] is 'l' the next-to-last char, and so on. Negative index numbers count back from the end of the string:</br>
62
+
>The standard zero-based index numbers give easy access to chars near the start of the string. As an alternative, Python uses negative numbers to give easy access to the chars at the end of the string: s[-1] is the last char 'o', s[-2] is 'l' the next-to-last char, and so on. Negative index numbers count back from the end of the string:
63
63
64
64
| <center>Function </center> | <center>What it does</center>
65
65
| :------------- | :-------------
@@ -72,15 +72,15 @@ text = 'The value of pi is ' + str(pi) ## yes
72
72
73
73
<h2>String %</h2>
74
74
75
-
>Python has a printf()-like facility to put together a string. The % operator takes a printf-type format string on the left (%d int, %s string, %f/%g floating point), and the matching values in a tuple on the right (a tuple is made of values separated by commas, typically grouped inside parentheses):</br>
75
+
>Python has a printf()-like facility to put together a string. The % operator takes a printf-type format string on the left (%d int, %s string, %f/%g floating point), and the matching values in a tuple on the right (a tuple is made of values separated by commas, typically grouped inside parentheses):
76
76
77
77
_**Example**_
78
78
```python
79
79
## % operator
80
80
text ="%d little pigs come out or I'll %s and %s and %s"% (3, 'huff', 'puff', 'blow down')
81
81
```
82
82
83
-
>The above line is kind of long -- suppose you want to break it into separate lines. You cannot just split the line after the '%' as you might in other languages, since by default Python treats each line as a separate statement (on the plus side, this is why we don't need to type semi-colons on each line). To fix this, enclose the whole expression in an outer set of parenthesis -- then the expression is allowed to span multiple lines. This code-across-lines technique works with the various grouping constructs detailed below: ( ), [], { }.</br>
83
+
>The above line is kind of long -- suppose you want to break it into separate lines. You cannot just split the line after the '%' as you might in other languages, since by default Python treats each line as a separate statement (on the plus side, this is why we don't need to type semi-colons on each line). To fix this, enclose the whole expression in an outer set of parenthesis -- then the expression is allowed to span multiple lines. This code-across-lines technique works with the various grouping constructs detailed below: ( ), [], { }.
Copy file name to clipboardExpand all lines: python/06-Lists.md
+8-8
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
<h1align="center"> Lists </h1>
2
2
3
3
## What are lists ?
4
-
> List is a collection in python. In most languages, it is called Array. We often need 'list' in our programs. Imagine you are writing a program to store name of every student in a class of 50 .
4
+
> List is a collection in python. In most languages, it is called an Array. We often need 'list' in our programs. Imagine you are writing a program to store the name of every student in a class of 50 .
5
5
6
6
> Elements in a list are stored in sequential order . Every element can be accessed by their index value .
7
7
@@ -24,23 +24,23 @@ player_scores = [ 78, 103, 200 , 57] # >>> Initialized list with Integers
24
24
player_names = [ "Karan" , "Chirag" , "Jay" , "Raj" ] # Initialized list with strings
25
25
```
26
26
27
-
> Unlike other programming languages , in python we can Initialized or store elements in a list which are of different datatypes . For example,
27
+
> Unlike other programming languages , in python we can Initialize or store elements which are of different datatypes in the same list. For example,
* The Python interpreter has a number of functions and types built into it that are always available.
4
-
* There is no need to import modules extra in order to use them.
4
+
* There is no need to import any extra modules in order to use them.
5
5
* A few functions that we will be covering here are-
6
6
* Map
7
7
* Filter
@@ -10,7 +10,7 @@
10
10
* Reduce
11
11
12
12
## Map
13
-
* It iterates through all the elements of a iterable and applies some specific funtion to each element of that iterable.
13
+
* It iterates through all the elements of an iterable and applies some specific function to each element of that iterable.
14
14
* With multiple iterables, the iterator stops when the shortest iterable is exhausted
15
15
16
16
### syntax
@@ -65,7 +65,7 @@ Output
65
65
## Sort/Sorted
66
66
* Python lists have a built-in sort() method that modifies the list in-place and a sorted() built-in function that builds a new sorted list from an iterable
67
67
* There are many ways to use them to sort data and there doesn't appear to be a single, central place in the various manuals describing them
68
-
* The key difference between both is that sorted returns a new list whereas sort chsnges the original list itself.
68
+
* The key difference between both is that sorted returns a new list whereas sort changes the original list itself.
69
69
70
70
### syntax
71
71
```python
@@ -78,7 +78,7 @@ sorted(list,key=<insert the key>)#sort in ascending order of the key set
Copy file name to clipboardExpand all lines: python/12-Modules.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ The Python installers for the Windows platform usually include the [entire stand
8
8
* os - operating system interfaces
9
9
10
10
11
-
> In addition to the standard library, there is a growing collection of several thousand components (from individual programs and modules to packages and entire application development frameworks), available from [PyPI](https://pypi.python.org/pypi) , which you are free to explore after getting comfortable using some of th built in modules .
11
+
> In addition to the standard library, there is a growing collection of several thousand components (from individual programs and modules to packages and entire application development frameworks), available from [PyPI](https://pypi.python.org/pypi) , which you are free to explore after getting comfortable using some of the built in modules .
12
12
13
13
### How do we use them ?
14
14
> We can import modules which are available under [standard library](https://docs.python.org/3/library/index.html) by using _from_ , _as_ and _import_ keyword .
0 commit comments