whenever we use input() the return value is always a string
indexing starts from 0
[:3] : returns a string from start to 3rd index but
excluding the calue at index 3.
[:-1] : -1 represents end of the string.
len()
string.upper()
string.lower()
string.find()
string.replcae()
check if a string contains a string : 'in' operator.
e.g. ('python' in course)
difference between in and find method is:
in returns the boolean value: true or false
find method returns the index of the characters.
---------------------------------------------------
Operators:
To learn python, we have two types of numbers:
whole numbers or integers or non-decimal
decimal or float
Augmented assignment operator : +=
x = x + 3
or
x += 3
Order of operators:
parenthesis
exponentiation
multiplication or division
addition or subtraction
================================================
Math Functions in Pythons
import math
round
abs (absolute function)
math.ceil(2.9)
math.floor(2.9)
you need to import math module
module is a separate file
E.g. each section in supermarket is like a module.
How to learn about all the functions in math module.
Google: python3 math module
======================================================
Loops
f"" is used for a formatted string
{} is used to dynmically insert values
while loop is used to execute a block of code multiple times.
DRY: Dont repeat yourself
while True : executes a condition until it experiences a break
For Loop: iterate over a number of items or a string
=================================
Methods in list
list=[5,2,1,7,4]
list.append(object)
list.insert(0,12)(index,object)
list.remove(object)
list.clear() will remove all the items from a list
list.pop() will remove last item in the list
list.index(5) will returm the index of the first occurence of 5 in this list.
if you pass an item which is not in the list then you will get an error :
list.index(50)
ValueError: item is not in the list
'in' operator to check for existence of a character or sequence in characters in a string.
It returns True and False as output
list.sort() method to sort items in a list.
it doesn't return any values it simply sorts the list in place.
None is an object in python when no value is returned.
list.sort()
print(list)
----------------------
list.reverse() will reverse the list
------------------
list2=list.copy()
list.append(10)
print(list2)
o/p: [5,2,1,7,4] so there is no effect on list2 if we append anything in list.
indexing starts from 0
[:3] : returns a string from start to 3rd index but
excluding the calue at index 3.
[:-1] : -1 represents end of the string.
len()
string.upper()
string.lower()
string.find()
string.replcae()
check if a string contains a string : 'in' operator.
e.g. ('python' in course)
difference between in and find method is:
in returns the boolean value: true or false
find method returns the index of the characters.
---------------------------------------------------
Operators:
To learn python, we have two types of numbers:
whole numbers or integers or non-decimal
decimal or float
Augmented assignment operator : +=
x = x + 3
or
x += 3
Order of operators:
parenthesis
exponentiation
multiplication or division
addition or subtraction
================================================
Math Functions in Pythons
import math
round
abs (absolute function)
math.ceil(2.9)
math.floor(2.9)
you need to import math module
module is a separate file
E.g. each section in supermarket is like a module.
How to learn about all the functions in math module.
Google: python3 math module
======================================================
Loops
f"" is used for a formatted string
{} is used to dynmically insert values
while loop is used to execute a block of code multiple times.
DRY: Dont repeat yourself
while True : executes a condition until it experiences a break
For Loop: iterate over a number of items or a string
=================================
Methods in list
list=[5,2,1,7,4]
list.append(object)
list.insert(0,12)(index,object)
list.remove(object)
list.clear() will remove all the items from a list
list.pop() will remove last item in the list
list.index(5) will returm the index of the first occurence of 5 in this list.
if you pass an item which is not in the list then you will get an error :
list.index(50)
ValueError: item is not in the list
'in' operator to check for existence of a character or sequence in characters in a string.
It returns True and False as output
list.sort() method to sort items in a list.
it doesn't return any values it simply sorts the list in place.
None is an object in python when no value is returned.
list.sort()
print(list)
----------------------
list.reverse() will reverse the list
------------------
list2=list.copy()
list.append(10)
print(list2)
o/p: [5,2,1,7,4] so there is no effect on list2 if we append anything in list.