Skip to content

KaviyaGopi/PYTHON

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

PYTHON-FEB

  1. What is python?
    ans) Python is a programming language

  2. 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)

  3. who is the father of python?
    ans) Guido Van Rossum:
    official DOB: Release date:20 th Feb 1991

  4. What is pre requisite to learn python?
    ans) nothing

  5. in olden days: c language
    I B.TECH / DEGREE : 1 SEM: C LANG
    PYTHON:

Features of Python:

  1. simple to learn, to code
  2. general purpose high level progr language
  3. multi paradigm
  4. interpreted
  5. opensource
  6. freeware
  7. dynamically typed programming language
  8. huge library support
  9. extensible
  10. embedded
  11. 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?

  1. italian movie-> totally dubbed -> telugu version - watch it: compiler
  2. 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

Free ware & open source software (FOSS):

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

flavours of python:

  1. cpython
  2. jpython / jython: to work with java application
  3. iron python: .net applications
  4. 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
  5. ruby python
  6. 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

  1. Platform independent: once if python program is developed, it will run on any platform:
    like on windows, unix, mac os, other

  2. 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

  3. Python is all rounder:
    python: procedure oriented features, object oriented features, modular programming features, scripting featres

  4. 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
  1. python is very simple & easy to code
  2. FOSS(FREE WARE & OPEN SOURCE SOFTWARE)
  3. General purpose high level programming language
  4. platform independent
  5. portable
  6. interpreted language: python is also compiled & interepreted
    yes, but compilation is done automatically
  7. 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

All the feature of python programming language:

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")

Identifiers:

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

Is there any specific rules to name an element:

name can contain: alphabets (lower case /upper case), digits, underscore (\_) rules:

  1. 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
  2. from 2nd letter onwards u can use either alphabet or digit or both
  3. no spaces are allowed
  4. if name contains multiple word we can use underscore (\_) to join them
  5. No other symbol is allowed except (\_)
  6. keywords cant be used for naming purpose

what is a keyword?

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

List of keywords in python:

  1. False
  2. None
  3. True
  4. peg_parser
  5. and
  6. as
  7. assert
  8. async
  9. await
  10. break
  11. class
  12. continue
  13. def
  14. del
  15. elif
  16. else
  17. except
  18. finally
  19. for
  20. from
  21. global
  22. if
  23. import
  24. in
  25. is
  26. lambda
  27. nonlocal
  28. not
  29. or
  30. pass
  31. raise
  32. return
  33. try
  34. while
  35. with
  36. 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

What are the various data types available in python:

  1. int
  2. float
  3. complex
  4. bool
  5. str
  6. None
  7. bytes
  8. Bytearray
  9. List
  10. Tuple
  11. set
  12. frozenset
  13. dict
  14. range

int:

  • 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

  1. 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)

  2. 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

In 4 ways:

  • 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:
  1. any number preceded by 0o (or) 0O is treated as octal number
  2. any number preceded by 0x(or) 0X is treated as hexadecimal number
  3. any number preceded by 0b(or) 0B is treated as binary number
interview board:

a=11 b=0o11 c=0X11 d=0B11

float

  • 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

complex:

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

bool:

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

str:

Anything/ collection of characters represented within :

  1. single quotes
  2. double quotes
    character: may be an alphabet(lower/upper), digit, white space character, spl symbol
    'pavan" ==> invalid
    '20th Feb 1991' ==> valid
  3. 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'

len():

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'

Data types:

  1. int
  2. float
  3. complex
  4. bool
  5. 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?

  1. single line comments: any line that starts with # is treated as comment line Note: compiler,pvm ignore the comment lines
  2. 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:

  1. %formatting
    %d - decimal integer
  2. format() method
  3. f string literal
  4. update to f string literal: newer vesion

Fundamental data types in python:

  • int
  • float
  • str
  • bool
  • complex

Type casting/coercion: conversion of one data type into another data type

1. int():

By using this function we can convert any other data type into int type

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

2. float():

built in function to convert any data type into float type

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'

3. bool():

it is a built in function to convert any other data type into bool type

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

True

  1. complex(): built in function to convert any data type into complex type

int to complex: yes
float to complex: yes
bool to complex: yes

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published