Make Notes from Youtube Videos
chapter 1
20:57
modules:- it is used if u have to run other code
two types of modules
I) built- in modules:- preinstalled in python
II) External modules:- need to install using pip
if u have to install any flask or os just put it
50:30
in the run section
"pip install flask
pip install os"
pip :- package manager for python u can use pip to install a module on your system (pip install flask
installs flask module)
24:56
REPL:- read- evaluate- print- loop
29:22
for comments
use ( # ) (pound single)
types of comments
1) single line comments - written using #
2) multi line comments - written using ('''comment''')
chapter 2
for string occupying more than 1 line than use triple quote(''') instead of double quote('')
Variables and data types
the variable is the name given to a memory location in a program. for example
a= "harry" --------- string
b= 345 ----------------- integer
c= 45.32 ----------------- float
variables = container to store a value
keywords = reserved words in python
identifiers = class/functions/ variable names
Data Types
primarily there are following data types in python
1) Integers -- 1,4,3,2 -2,-3 ,0 etc....
2) Floating- point numbers -- 1.2, 3.4 ,5.6 etc
3) strings --- no of characters enclosed in single (') double('') and triple quote (''')
3) strings --- no of characters enclosed in single (') double('') and triple quote (''')
4) booleans ------- true or false (sach or jhuth)
5) none ------- (much nahi ko return kare function)
don't use reserved keywords as a variables
like import, true, false etc......
50:30
52:25
booleans
#printing the variables
print(a)
print(b)
print(c)
print(d)
# printing the type of variables
print (type(a))
print(type(b))
print(type(c))
print(type(d))
56:23
57:31
Rules for defining a variable name-- > also applies to other identifiers
1) A variable name can contain alphabets, digits, and underscores.
2) A variable name can only start with an alphabet and underscore.
3) A variable name cant start with a digit.
4) no while space is allowed to be used inside a variable name.
identifiers -- class/ function/ variables name
Examples of a few variable names are:-
vaibhav, one8, seven, -seven etc,.
Operators in python
following are some common operators in python.
1) Arithmetic operators :- +,-,*,/ etc
2) Assignment operators :- =,+=,-= etc.
3) comparison operators :- ==, >, >= ,< ,!= etc
4) Logical operators :- and , or, not
01:06:16
Arithmetic operators
01:03:07
variable names are case sensitive
Assignment operators
a= 34
a += 12
print(a)
ans 46
or if a -= 12
print(a)
ans 22
a *=12
a /=12
print(a)
comparison operators
01:10:11
01:09:36
#comparison operators
b = (14>=7) > or =
b = (14>=7) > or =
print(b)
and True
all operators
==
<=
>=
!= (not equal to)
#LOGICAL OPERATORS
01:11:55
(and )-- tb true return Karega jb 2ono true honge baaaki saare cases m false return Karega
(or) ---- tb true return Karega jb 2ono m see koi 1 true ho Jaye
not ------ used for only one variable
(typecasting and type functions)
type function is used to find the data type pf a given variable in python.
01:15:52
01:16:20
01:16:35
Typecasting = it is a way to convert 1 datatype to another 01:17:29
01:19:28
if ''31'' is a string literal and 31 is a numeric literal.
input() function
this function allows the user to take input from the keyboard as a string
a = input("enter name") ---> if a is ''Harry'', the user entered harry
01:21:45
input string k taur pr legal ...
01:22:40
01:23:23
01:23:39
% this operator gives reminder
01:30:15
01:31:23
01:35:20
01:36:03
nice question no 5 (do it by yourself)
01:33:19
01:36:43
chapter 3 (strings)
01:39:22
01:43:26
don't confuse python single quote or double quotes m , safely use karo bro
01:44:38
string slicing
01:45:18
name = "vaibhav roy"
greeting = good morning"
#print(type(name))
#concatenating two strings
#also u can do this
c = greeting +name
print(c)
01:48:40
01:48:49
string indexing
A string in python can be sliced for getting a part of the string.
Consider the following string
name = vaibhav ------> length =7
indexing of name
VAIBHAV
0123456 (indexing) (indexing... it starts from 0)
the index in a string starts from 0 to (length -1)
in python. In order to slice a string, we use the following syntax.
sl = name[ind_ start : ind_ end]
ind_start ----> first index include
ind end ---> last index is not include
sl[0:3] returns "vai" ----> character from 0 to 3
sl[1:3] returns "ar" ------> character from 1 to 3
00:00
square bracket inside print [] gives u the index word
like name = "vaibhav"
print(name[0])
ans = V
00:00
00:00
00:00
name[3] = "d" ---> Does not work
00:00
string slicing
print(name[0:3])
ans = vai
00:00
print(name[1:4])
00:00
00:00
00:00
00:00
negative indexing
VAIBHAV
-7-6-5-4-3-2-1
slicing with skip value
we can provide a skip value as a part of our slice like this:
word = ''amazing"
word[1:6:2] ---------> 'mzn
00:00
00:00
00:00
00:00
00:00
00:00
00:00
00:00
00:00
(ii)[Link]("notes") ------> This function tells whether the variable strings end with the string
"notes" or not. if string is "story" , it returns true for "notes" since story ends with notes
00:00
00:00
(iii) [Link]("c") ---> counts the total number of occurrence of any character
00:00
00:00
calculating total no of a or occurance
00:00
00:00
(iv)[Link]() ------> this function capitalize the first character of a given string.
00:00
(v) [Link](word) --------> this function finds a sword and returns the index of the first occurrence
of that word in the string.
00:00
00:00
00:00
00:00
(vi) [Link]( oldword , newword ) ------> the function replaces the oldword with newword in the
entire string.
00:00
00:00
New line character
story = "harry is good. \nHe\t is very good"
print(story)
00:00
Escape sequence characters
sequence of characters after backlash'\' ----> Escape sequence characters
Escape sequence character comprises of more than one character but represents one character
when used within the strings.
Examples \n , \t, \ , \\ etc
\n ----> newline
\n ----> newline
\t -------> tab
\' ---------> single quote
\\ ---------> backlash
00:00
practice chapter 3
02:17:16 problem no 1
ans
02:19:14
problem 2
02:20:11
ans
02:25:53
problem 3
02:26:14
ans
02:28:49
(generally we use affle)
it will show -1 if it cant find anything
ans 4
02:31:47
ans 5
02:34:01
chapter 4
(Lists and tuples)
notes
02:35:24
in list the index also starts from 0 only
02:38:33
print the list using print function
02:39:15
02:40:30
02:40:30
we can change index in lists
02:40:48
02:41:06
we can create a list with items of different types
02:41:54
02:42:20
02:43:21
02:45:02
#we can create a list with items of different types
c =[34 ,"harry" , false, 6.9]
print(c)
#list slicing
friends = ["harry" ,"Tom", "Rohan" , "Sam" ,"Divya" , 45]
print(friends[0:4])
print(friends[-4:])
02:45:55
02:46:01
02:47:11
#list methods
02:47:58
02:47:58
sorting(mtlb badhte karam mai lagana)
02:48:48
02:50:17
02:51:07
02:51:31
02:51:58
append is used for add to the end of the list
02:53:02
02:53:19
#insert
02:53:48
02:54:13
[Link](0,544) ---- 544 will be added at the 0 index.
02:54:59
02:55:04
02:55:04
example [Link](2)---- index no 2 wala delete ho jaayega
02:55:37
[Link](21)---- 21 lists se delete h jaayega
02:56:12
lists have 2 much methods
we can find other methods of lists on search "python docs" on google go to documentation
02:57:36
Tuples
t = (1,2,3,5)
print(t[0])
difference between tuples and lists is that
we cant change tuples but we can change lists
#we cannot update the values of tupples
t[0] = 34
03:00:14
immutable = cannot change
#creating a tuple using ()
t = (1,2,3,4)
t1 = () --- empty tupple
print(t1)
return ()
t1 = (1) # Wrong way to declare a tuple with single element
t1 = (1,) # Tupple with single element
print(t1)
return 1
#printing the elements of a tuple
print(t[0])
#cannot update the values of a tuple
03:01:4603:02:32
þÿ03:01:46
03:02:59
03:03:11
03:03:14
03:03:21
#Tupple Methods
count method
t = (1,2,4,5,1,3,1,2,3,2,1)
print([Link](1))
print([Link](1))
return 4
count --- it just count that how many time the number occurs in that
Index Method
a index(1) : a index(1) will return the index of first occurrence of 1 in a
03:05:14
#Practice set
03:07:15
ANS 1:- Store_fruits
#vs code m alt daba k curser kahin rakhde to
wo change hogi value jaha chahe waha pr.
03:10:05
03:10:17
ctrl + enter apne aap nayi line m aa jaoge in VS
code.
code.
03:11:40
03:12:39
#list k ander repetitive values bhi likhte hainn to use koi farak
nahi padta hai.
Ans :2
03:14:04
but it is a string so that we have to make it integer change it integer
03:14:46
03:15:52
Ans 3 Tuple change test
Ans 3 Tuple change test
03:16:54
hence proved
python m har chiz object hai.
ye object support nahi krta item assignment
Ans 4 ) write a program to sum a list with 4 numbers.
a =[2,4,5,67]
print(a[0] + a[1] + a[2] + a[3])
print(sum(a))
return 78
03:18:28
question 5 do it yourself
.count() ka use krke.
'