-
What is python?
ans) Python is a programming language -
what is a progra language?
Programming Language is a computer language using which we can write instructions (using computer language we can write some instruction , which will executed by computer) -
who is the father of python?
ans) Guido Van Rossum:
official DOB: Release date:20 th Feb 1991 -
What is pre requisite to learn python?
ans) nothing -
in olden days: c language
I B.TECH / DEGREE : 1 SEM: C LANG
PYTHON:
- simple to learn, to code
- general purpose high level progr language
- multi paradigm
- interpreted
- opensource
- freeware
- dynamically typed programming language
- huge library support
- extensible
- embedded
- platform independent
computer: communication channel
channel: computer language: those languages are classified into 2 types:
- low level,
- high level
Low Level: It is not user friendly or programmer friendly
eg : 1010111101010
       0011010100010
       1110101011111
High Level: programmer friendly (Programmer feeling very comfortable such languages are called as hight level language)
eg : x=10
y=20
z=x+y
Python is General Purpose High level Programming language:
high level lang: user / programmer friendly
Q: Why all high level languages are user friendly?
ans: we use english letters, & mathematicals symbols etc to write the program
Q: bengali ====> english
in this case : translator: who can translate bengali statement into english statements
if i write the program by using english like alphabets(H.L.L) =====> HOW COMPUTER CAN UNDERSTAND UR PROGRAM
Translator: compilers, interpreters
Translator 1: all at a time: compiler
Translator 2: line by line: interpreter
Italian movie: excellent: watch this movie(telugu)
how many ways are there to watch this movie?
- italian movie-> totally dubbed -> telugu version - watch it: compiler
- if it is not dubbed-> atleast if i get subtitles in telugu: watch it: interepreter
examples for H.L.L: C,C++,.NET,JAVA,PYTHON,APEX etc
c,c++ ===> compiled languages
python: interpreted language
java: both compiled & interpreted
In python: compilation is done implicitly and then interpretation is done
Most of the H.L.L are developed to design some specific applications only
desktop application/stand alone applications: i have to compulsory install the s/w in ur computer web applications: any application tht follows client:server model
www.flipkart.com
www.google.com
www.gmail.com
www.amazon.com
games, IOT APPLICATIONS,machine learning applications,robotics applications data science, network applications,AI applications etc
Which companies are using python? youtube, facebook, twitter, instagram,github,dropbox ,google,amazon etc
Freeware:
VENDOR FOR JAVA ==> Oracle corporation
until java10 version: free of cost: for commercial purpose
but from java 11: u r supposed to pay: Oracle corporation
vendor for .net ==> Microsoft
compulsory: u have to pay some amount :
python: is absolutely for free of cost:
PSF: PYTHON SOFTWARE FOUNDATION: NON PROFITABLE ORGANIZATION
OpenSource: implementation of python program langu: is open to all
chemical equations : pharmaceutical : customize python acc to ur requirement: new flavour of python:pharmapython
bought a house from a builder: buyer is not satisfied : customize the house as per requirement
- cpython
- jpython / jython: to work with java application
- iron python: .net applications
- pypy: when compared to the compiled languages, interpreted languages are from performance point of view they r not upto the mark: to overcome this problem : JIT: JUST IN TIME COMPILER
- ruby python
- anaconda python:sometimes i want to handle , analyze very huge amount of data:
throughout the world : flipkart , amazon: billions of people
windows: o.s: u cant customize: is not open source
unix: os: Linux, Redhat, ubuntu, hp linux: flavours: open source
-
Platform independent: once if python program is developed, it will run on any platform:
like on windows, unix, mac os, other -
portable: wihtout making any changes to developed python program happily u can port ur python program
to some othe system with differnt architecture ... ur python program will work for sure -
Python is all rounder:
python: procedure oriented features, object oriented features, modular programming features, scripting featres -
python is interpreted program language
Q: python is not open source?
yes|no:
ans: no, python is open source
Q: for python several flavours are available in the market because
it is freeware?
no, several flavours are possible : this is because of open source
1. cpython
2. jython
3. iron python
4. anaconda python
5. pypy
6. ruby python
if I install python in my computer which flavour will come:
ans: cpython
what is official website to download python software?
www.python.org
PSF: PYTHON SOFTWARE FOUND: PROFITABLE ORGANIZATION
NO, NON PROFITABLE ORGANIZATION
which of the following is compiled language?
1. python 2) java 3) c 4) all the above
ans: c language
in which of the following language compilation need not be performed by user explicityly?
1. python 2) java 3) c 4) all the above
ans: python
Q: compiler can check for which type of errors?
ans:
a) run time b) logical errors c) syntax erros d) all
for every programming language: set of rules & regulations: syntax
- python is very simple & easy to code
- FOSS(FREE WARE & OPEN SOURCE SOFTWARE)
- General purpose high level programming language
- platform independent
- portable
- interpreted language: python is also compiled & interepreted
yes, but compilation is done automatically - dynamically typed progra lanaugage: in python we r not required to specify the type of the variable at the time of its declaration
c,c++,java: statically typed programming language means every variable must be declared along with data type
float avg=6.35
Am i required to specify the type of data explicitly in python?
ans: not required, python dynamically typed prog langu
x='iam teaching python'
String msg="iam teaching python";
msg=99.6; not allowed in other progr languages
but it is possible in python
In Python Backward compatibility is not possible:
from python 3.x version: print("hello")
A program is a collection of so many elements
for some elements in the program we r supposed to give some name
Those named elemets referred as Identifier
In python program for which elements we r supposed to give name?
- variable
- functions
- methods
- modules
- package
- objects
- class etc
name can contain: alphabets (lower case /upper case), digits, underscore (\_)
rules:
- always name must start with an alphabet only(lowercase/upper case), underscore also allowed ( but not recommended) can i start a name with underscore: yes
- from 2nd letter onwards u can use either alphabet or digit or both
- no spaces are allowed
- if name contains multiple word we can use underscore
(\_)
to join them - No other symbol is allowed except
(\_)
- keywords cant be used for naming purpose
is a reserved word : we are not allowed to use keywords for naming any element
total : 36 keywords
self=58.369: they r assuming that self is a keyword :
ans: self is not a keyword
- False
- None
- True
- peg_parser
- and
- as
- assert
- async
- await
- break
- class
- continue
- def
- del
- elif
- else
- except
- finally
- for
- from
- global
- if
- import
- in
- is
- lambda
- nonlocal
- not
- or
- pass
- raise
- return
- try
- while
- with
- yield
note: python is case sensitive languae
Why do we write a program?
ans: to process the data
Where do we store the data?
ans: data will be stored in computer memory
Q) what is a variable?
- is a container that contains some data
- data storage area where we can store our required data
- named memory location that holds our data
Q) which kind of data that i can store in a variable?
ans: u can store any type of data that is supported by ur python language
- int
- float
- complex
- bool
- str
- None
- bytes
- Bytearray
- List
- Tuple
- set
- frozenset
- dict
- range
- any number without decimal part is treated as int type:
ex: 45, 9999, -87541
x=45 : but in python at the time declaring a variable, we need not to mention
the data type explicitly
int x=45 : statically type programming language
Frequently used function in python:
every function will do some specific task
-
type(): built in function
the job/task of the function is .... it will return type of variable that u passed as an argument
ex:
type(x): this is function usage/calling statement:at the time of calling a function what ever inputs
u r supplying : will be treated as a "argument"
avg=99.89
type(avg) -
id(): job/task of this function: it will return address of the argument
ex:
marks=56
total=458
avg=99.99
integers: decimal, octal, hexadecimal numbers system
- any integer in decimal system: 0 to 9
base 10 - any integer in octal system: 0 to 7
base 8: - note: in this number system no scope for digits: 8,9
any integer in hexadecimal system: 0 to 9 (10) + 6 (a,b,c,d,e,f)
a-10
b-11
c-12
d-13
e-14
f-15
integer: binary form also: in binary number system we have only 0 & 1 Note:
- any number preceded by 0o (or) 0O is treated as octal number
- any number preceded by 0x(or) 0X is treated as hexadecimal number
- any number preceded by 0b(or) 0B is treated as binary number
interview board:
a=11 b=0o11 c=0X11 d=0B11
- any number with decimal part is treated as float type
- it can be represented in two ways:
- fixed representation ex: 5.3,0.001
- scientific notation/exponential form ex: M e Exponent ==> M x 10 ^ exponent
in any other language: c, c++, java there is not built in support for this data type
in our mathematics: 2+3i, 9-i8 is valid but in python it is invalid
user defined data type: struct(c,c++), class(in c++,java,python etc)
in python: complex number must be represented like:
a+bj (or) a+bJ
here a represents real part: it may be int / float type
here b represents imag part: it may be int / float type
we can add,subtract,multiply,divide complex numbers also
we can perform power operation on complex numbers
True, False values are treated as bool type
Note:
intenally True is considered as 1
internally False is considered as 0
+,-,\*,/
operations on bool values:
all the above operations are possible on bool type
Anything/ collection of characters represented within :
- single quotes
- double quotes
character: may be an alphabet(lower/upper), digit, white space character, spl symbol
'pavan" ==> invalid
'20th Feb 1991' ==> valid - triple single/double quotes: are useful to represent multiline string literal
ex: details=""" iam learning
... core python from pavan
... sir
... & teaching is easy to understand
... this is my first
... programming language
... very useful
... & helpful """
ex:
info=''' My bank name
... is SBI
... & having
... savings account
... in chirala
... branch'''
type(info)
OUTPUT:
<class 'str'>
internally all the elements of the string will be given a number:
known as subscript/index
index : either +ve or -ve
+ve represent: forward direction
-ve represent: reverse direction
faculty='M.PAVAN'
faculty[0]
OUTPUT: 'M'
Is a built in function which will return the length of the argument
ex: faculty='M.PAVAN'
len(faculty): function calling
at the time of function calling, input supplied is treated as argument
alp="abcdefghijklmnopqrstuvwxyz"
type(alp)
OUTPUT:
<class 'str'>
msg='pavan sir teaching core python course'
len(alp)
OUTPUT:
26
ac='PAVAN SIR'
len(fac)
OUTPUT:
9
alp='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp[12]
OUTPUT:
'M'
len(alp)
26
operator: is a symbol that is used to perform some operation on the data operand: is the data on which operation is carried out
pavan '+'sir'
'pavan sir'
here + is called as concatenation operator
10*20
200
here * is multiplication operator
*uif \_
is used as repetition operator : one operand must be str type & other operand must be int only \*
slicing: with slicing we can access required portion of the string
variable_name[begin:end:step ]: it will return from begin to end-1 only
in the above index: step is optional
alp[7:10]
OUTPUT: 'HIJ'
alp[7:11]
OUTPUT: 'HIJK'
alp[7:10000]
OUTPUT: 'HIJKLMNOPQRSTUVWXYZ'
If the specified value for end_index is out of range then python by default consider len(str) value for end index
alp[-500:26]
OUTPUT: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
In this case begin index is out of range, however python never raise any error because it will consider default value for begin index
which is "0"
alp[:10]
OUTPUT: 'ABCDEFGHIJ'
In this case also default value for begin index is considered, if u dont specify any value for begin index
alp[22:]
OUTPUT: 'WXYZ'
If u wont specify any value for end index: default value will be considered: len(str)
alp[:]
OUTPUT: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
Here default values for both & end index will be considered default value for step: is always +1
alp[0:26:2]
OUTPUT: 'ACEGIKMOQSUWY'
alp[::10]
OUTPUT: 'AKU'
alp[::7]
OUTPUT: 'AHOV'
beg:end:+1 ===> beg to end-1 if the step value is negative: means that accessing the string in reverse direction beg:end:-1 ====> beg to end+1
alp[-5:-11:-1] -5 to -10
alp='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp[-5:-11:-1]
OUTPUT: 'VUTSRQ'
OUTPUT: 'ZYXWVUTSRQPONMLKJ'
default value for beg index: -1 if step value is negative
alp[-1::-1]
OUTPUT: 'ZYXWVUTSRQPONMLKJIHGFEDCBA'
default value for end index: -(len(str)+1) if step value is negative
alp[::-1]
OUTPUT: 'ZYXWVUTSRQPONMLKJIHGFEDCBA'
- int
- float
- complex
- bool
- str
All the above data types are considered as fundamental data types in python:
output statement: if u want to print something on console, generally we use output statement in python python provides a built in / predefined/readymade function called as print() function
syntax: print(str)
ex:
print('M.PAVAN')
Note: to add comment line to your program in python we use # symbol but this is for single line comments only
Argument: is nothing but input supplied to the function call statement How to create comments in python?
- single line comments: any line that starts with # is treated as comment line Note: compiler,pvm ignore the comment lines
- Multiline comments: all the comment lines must start&ends with '''
Can I pass more than one input/argument to the print?
ans: yes,but all the arguments must be seperated by comma(,)
Note: but while printing all these arguments to the console python will seperate all these argments bydefault with a space character
Backslash characters: (escape characters) any backslash character takes the following form:
`\n` - newline
`\t` - tab character ( 1 tab=8 spaces)
sep - parameter
end- parameter
String interpolation: substituting the value of variable with in a string
It can done in various ways:
- %formatting
%d - decimal integer - format() method
- f string literal
- update to f string literal: newer vesion
- int
- float
- str
- bool
- complex
float to int : yes
bool to int : Yes
complex to int : no
str to int : yes
Note: str must contain integer value only represented in base 10 format
int(1.25)
OUTPUT: 1
int(True)
OUTPUT: 1
int(False)
OUTPUT: 0
int(2+3j)
OUTPUT: Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to int
int ==> float : yes
complex ==> float : no
bool ==> float : yes
str ==> float: yes
Note: str must be either integer value or float value
float(5)
OUTPUT: 5.0
float(2+3j)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float
ValueError: could not convert string to float: 'one.two'
int to bool: yes
float to bool: yes
complex to bool: yes
str to bool: yes
bool(25)
OUTPUT: True
bool(0)
OUTPUT: False
bool(-9)
OUTPUT: True
- complex(): built in function to convert any data type into complex type
int to complex: yes
float to complex: yes
bool to complex: yes