Skip to content

Commit 0aad919

Browse files
Add files via upload
1 parent 67b7efd commit 0aad919

27 files changed

Lines changed: 1505 additions & 0 deletions

00. Comments.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Comments
2+
3+
# This is single line comment
4+
5+
"""
6+
This
7+
Is
8+
Multiple
9+
Line
10+
Comment
11+
"""

01. Print.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Print
2+
3+
print ("Hello World")
4+
print ("2 Print")
5+
6+
# Print automatically adds new line
7+
8+
print()
9+
10+
print ("Hello World", end = "")
11+
print ("Second Print")
12+
13+
# end function can also be use to put other values
14+
15+
print()
16+
17+
print ("Hello World", end = " Hii ")
18+
19+
20+
# After using end you have to put 2 print to skip a line
21+
22+
print()
23+
print()
24+
25+
# Print can also handle multiple statements
26+
27+
print("Hello World", "Second Print")
28+
29+
# To print something multiple times we multiply it by the number.
30+
31+
print(2 * "Hello World ")
32+
print()
33+
34+
# Only string could we written multiple times using the multiplier
35+
36+
a = 12
37+
b = 82
38+
39+
a, b = b, a
40+
41+
print(a, b)
42+
print()
43+
44+
# To interchange the values
45+
46+
47+
""" Compact print statement """
48+
49+
print( int (input("Entre your first number : ")) + int (input("Entre your second number : ")) )
50+
51+
# We could also give a input arguement inside the print

02. Escape Sequence Character.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Escape Sequence Character
2+
3+
print("Hello \nWorld")
4+
5+
# \n is a new line character
6+
7+
print("Hello \\n World")
8+
9+
#\\n to write \n
10+
11+
print ("Hello \"World")
12+
13+
#\" to write "
14+
#\' to write '
15+
16+
print("Hello \t World")
17+
18+
# \t inserts a tab

03. DataTypes.py

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
# DataTypes
2+
3+
print(type("Hello World"))
4+
print()
5+
6+
# Type function give the type of the data stored
7+
8+
var1 = "41"
9+
var2 = "57"
10+
11+
print(var1 + var2)
12+
13+
# Addition of two strings concatinate them
14+
15+
print(int(var1) + int(var2))
16+
17+
# Int() function can change any data type into integer if possible
18+
19+
"""
20+
Similarly, we have :
21+
22+
str()
23+
float()
24+
25+
"""
26+
27+
# we could also multiply the number in int statement
28+
29+
print(2 * int(var1) + int(var2))
30+
31+
32+
33+
# Strings
34+
35+
mystr = "Hello World"
36+
37+
print (len(mystr))
38+
print()
39+
40+
# len() gives the length of the string (no. of characters)
41+
42+
43+
""" String Slicing """
44+
45+
print(mystr[0])
46+
47+
# If we want a particular character of the string we can write the place of character in a big bracket after string name
48+
49+
# In programming number starts from 0
50+
51+
print(mystr[0:5])
52+
53+
# This is used when we want a particular part to the string by using : between the start and end character
54+
55+
# The upper valuse in included but lower value in excluded
56+
57+
print(mystr[0:11:2])
58+
59+
# The the second : represents the no of characters to be skipped
60+
61+
# 2 means it only shows every second character after the previous one
62+
63+
64+
""" Blanks """
65+
66+
print(mystr[8:])
67+
68+
# Leaving any space blank will take the extreme position of it
69+
70+
# Example
71+
72+
print(mystr[ :11])
73+
74+
# Blank was taken as 0
75+
76+
print(mystr[ : : ])
77+
78+
# Leaving second : blank will take is as 1
79+
80+
81+
""" Negatives """
82+
83+
print(mystr[-8:-1])
84+
85+
# - reprents the counting from the last
86+
87+
# -0 doesn't exist so the number here satrt from -1
88+
89+
print(mystr[ : : -1])
90+
print()
91+
# Taking the number after second : in negative will reverse the string
92+
93+
94+
""" Functions """
95+
96+
print(mystr.isnumeric())
97+
print()
98+
99+
# .isnumeric() tells us whether the string is numeric or not
100+
101+
# Is is a Boolean datatype so, it answers only in true and false
102+
103+
"""
104+
Similarly, we have
105+
106+
.isalpha()
107+
# Check about alphanumeric
108+
109+
.endswith()
110+
# Check where it ends with given characters
111+
112+
.count()
113+
# Count the number of characters
114+
115+
.capitalize()
116+
# Capitalise the first letter
117+
118+
.find()
119+
# Find the position of the characters
120+
121+
.lower()
122+
# Decapitalise the whole string
123+
124+
.upper()
125+
# Capitalise the whole string
126+
127+
.replace("" , "")
128+
# Take two arguments 1. to replace 2. with what
129+
130+
"""
131+
132+
params = mystr.split(" ")
133+
print(params)
134+
print()
135+
136+
# .split() takes one arguement and splits the string into different part according to arguements and make a list out of it
137+
138+
139+
""" F strings """
140+
141+
a = "Harsh"
142+
print("This is %s" %a)
143+
144+
# %s represents the place where we want to add variable
145+
146+
# After the string %variable inserts the value
147+
148+
# This is suitable for few variables but not for a huge amount
149+
150+
print(f"This is {a}")
151+
print()
152+
153+
# Writting f before string makes it f string
154+
155+
# Use of { } inside the f string to specify the variables in the space
156+
157+
# We could also give any operation inside f string
158+
159+
160+
""" Raw String """
161+
162+
print(r"\n This is a raw string")
163+
164+
# raw string is made using r before " "
165+
166+
# raw string behave like a string without any escape sequence character and variable names

04. Input.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Input
2+
3+
Inp = input()
4+
print(Inp)
5+
print()
6+
7+
# Input() takes input from the user in string format
8+
9+
# To use it as Integer we can use int()
10+
11+
IntInp = int(input())
12+
print(IntInp)
13+
print()
14+
15+
# But then it will only accept integer value not string
16+
17+
inpu = input("Entre Your Name : ")
18+
19+
# You can also write a print statement inside input which will work same as print command
20+
21+
# But input only takes 1 argument

05. List.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# List
2+
3+
var = [ "Harsh", "Ankit", "Amit", "Priyansu" ]
4+
print(var)
5+
print()
6+
7+
# List is written in [ ]
8+
# All the values inside the list are taken as integer
9+
10+
""" List Slicing """
11+
12+
print(var[2])
13+
print(var[2:4])
14+
print(var[1:4:2])
15+
print()
16+
17+
# Works same as string
18+
19+
# Works with negative too but not recommended to take more than -1 because sometimes it throws error
20+
21+
var[2] = "Anubhav"
22+
print(var)
23+
print()
24+
25+
# Replaces the desired value from given
26+
27+
28+
""" Functions """
29+
30+
print(len(var))
31+
print()
32+
33+
# Prints length
34+
35+
# We also have
36+
37+
# min() lowest number, First word
38+
# max() highest number, Last word
39+
40+
var.sort()
41+
print(var)
42+
43+
# Sort fuction sorts the list in ascending
44+
45+
# In the case of list you have to first use function then print
46+
47+
#Similarly, we have
48+
49+
var.reverse()
50+
print(var)
51+
52+
# This will reverse the order of list
53+
54+
var.append("Prakhar")
55+
print(var)
56+
57+
# Append means add at the last
58+
59+
var. insert(3, "Sahil")
60+
print(var)
61+
62+
# Inserts the value at desired position
63+
# Take two arguments: 1. Position, 2. Value
64+
65+
var.remove("Harsh")
66+
print(var)
67+
print()
68+
69+
# Removes the given value from the list
70+
71+
a = ", ".join(var)
72+
print(a)
73+
74+
# .join function joints the items in the list with the arguement given before
75+
76+
77+
""" Comprehension """
78+
79+
ls = [ i for i in range(20) if i%3 == 0 ]
80+
print(ls)
81+
82+
# we could also make a list by using this method
83+
84+
# First arguement takes the variable name
85+
86+
# Second - position of variable
87+
88+
# Third - condition
89+
90+
# We could also give 1, 2 arguements only

06. Tupple.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Tupple
2+
3+
var1 = ("Harsh", "Ankit")
4+
print(var1)
5+
6+
# Tupples are written inside the ( )
7+
# The values of tupple can't be changed

0 commit comments

Comments
 (0)