Introduction
Introduction
-
-
#
28 , 29 30 , 30 5 .
...
*
compiler , interpreters
language ,
indentifiers , procedures ,
types ,
function reference
collections
L
Fundamentals Functions Numpy
&
- -
--- -
-
pythor ,
variable , functions map/filter/reduce - ..
data
processing
Introduction
-
Functional Programming Pandas
- - -
- -
Compier +
interpreter ,
SDK ,
IDE is
object primorphism , .
- -
-
Setup OOP
- -
- -
- -
Data Analysis
numeris , list , set , dictionary ,
bool module
,
Book matplotlib ,
seaborn
maths ,
relational ,
logical bitwise
,
closan
decorate
generator ,
,
metaclass selenium
Aop
Operators Advanced Features Testing
-
- -
-
- - -
control iterative ,
executes flask REST selenium ,
Beautiful Soup: Scrapy
, ,
Statements
- -
Web Services -
Web Scrapping
- -
About Instructor
§ 16+ years of experience
-
§ Freelance Developer
-
- -
--
- - -
-
-
--
- -
- -
-
>
Language
Fundamentals
=
--
What is a computer language?
=
-
iron
§ A language is a medium to interact with computer
----
·
§ Types
§ Machine languages: the code written in 0s and 1s and can be directly executed by CPU
① -------
instruction
O
2 § Assembly languages : a language closely related to one or a family of machine languages, and which uses mnemonics
& - -
to ease writing
- - - - - - -
CDO family
·Is ARISC
SPARC
-
As
§ Programming languages
, ,
§ General purpose languages: a programming language that is broadly applicable across application domains, and lacks
Ct ,
Is
,
Pythonjava
,
-
CIF UANL
,
-
XML
MiralGrest
,
§ Markup languages: a grammar for annotating a document in a way that is syntactically distinguishable from the text
,
S
§ Stylesheet language: a computer language that expresses the presentation of structured documents
-
S ML
*§ Configuration language: a language used to write configuration files
umt
/
json
, - -
§ Query language: a language used to make queries in databases and information systems
-
sah <S
JS Ruby § Scripting languages : a language used to write simple to complex scripts
,
- -
puthonDeal
,
,
PH4 ,
Az
10000
--
+ 20000 -
Al
data ⑭
El
#oran
-
Assemblylanguage
e
storage
- -
e
collection
machine language
-
current
CPU-Electric
-
Low Level vs High Level Languages
- -
Father
- -
os independent
faster
-
↓
file asm code
object
A
-
-
---
( .
obj)
↓ -
Libraries asm code
lit
↓
definitions
#
Linker
#issue
. . .
pative
- -
.....
- -
& & -
Executable ...........
-
- -
OS dependent
-
magic number
Executable file format
--
ELF
② Linuf
-
>
-
-
② macos I Mach-O
- -
-
Compiled language
--
--
§ A programming language which involves an executable to execute the logic instead of executing the
source code directly
§ E.g. C, C++, Pascal, Objective-C, Swift etc.
§ Stages
§ Pre-processing
§ Used to preprocess the code
§ Comments removal
§ Code expansion
§ Conditional compilation
§ Compiling
§ Compiler is used to translate pre-processed code into assembly instructions specific to the target processor architecture
§ Assembling
§ Assembler is used to translate the assembly instructions to object code
§ Linking
§ Linker used in this stage re-arranges the code and insert missing files to emit an executable
Interpreted Language
- -
--
§ A language mostly executes source code directly and freely, without previously compiling a programm
into an executable
§ E.g. Python, JavaScript, Perl, BASIC etc.
§ Interpretation
§ Interpreter used in the language executes the high level source code directly
Compiler vs Interpreter
Compiler Interpreter
The compiler is faster, as conversion occurs The interpreter runs slower as the execution
before the program executes. occurs simultaneously.
Errors are detected during the compilation Errors are identified and reported during the
phase and displayed before the execution of a given actual runtime.
program.
Compiled code needs to be recompiled to run Interpreted code is more portable as it can run
on different machines. on any machine with the appropriate
interpreter.
It requires more memory to translate the It requires less memory than compiled ones.
whole source code at once.
Debugging is more complex due to batch Debugging is easier due to the line-by-line
processing of the code. execution of a code.
Python
-
--
>
- console
Introduction
I
>
-
>
-
GUI
websites
*
Python
-
§ Procedural programming -
-
-
> scripting
Mar,agement
§ Functional programming
-
§ Heavily dependent on indentation to create blocks which makes it very easy to read the code
----
§ It has more than 300,000 packages included with wide range of functionality
----
§ Graphical user interfaces
-
↑
Skinter
-
§ Web frameworks
- - -
-
Flask/Dango
§ Networking
-
>
- Det/socket
§ Automation >
- Selenium
selenium/Bs) Scrapy
-
§ Web scraping
- - -
~
History
-
§ Van Rossum continued as Python's lead developer until July 12, 2018
------
§ When he announced his permanent vacation from his responsibilities, a team of five members was
developed in Jan 2019 to lead the project
- - - - - -
--- >
-
Advantages of Python
-
§ Python is simple to use, but it is a real programming language, offering much more structure and
support for large programs than shell scripts or batch files can offer
§ Python also offers much more error checking than C, and, being a very-high-level language, it has high-
level data types built in, such as flexible arrays and dictionaries
§ Because of its more general data types Python is applicable to a much larger problem domain than Awk
or even Perl, yet many things are at least as easy in Python as in those languages
§ Python allows you to split your program into modules that can be reused in other Python programs
§ Python is an interpreted language, which can save you considerable time during program development
because no compilation and linking is necessary
§ Python enables programs to be written compactly and readably
§ Programs written in Python are typically much shorter than equivalent C, C++, or Java programs, for
several reasons:
§ the high-level data types allow you to express complex operations in a single statement
§ statement grouping is done by indentation instead of beginning and ending brackets
§ no variable or argument declarations are necessary
Differences between Python and C Language
C Language Python
§ Having features like classes with inheritance, exception handling, functions etc.
§ One of the major versions of python
§ Version 1 [Jan 1994]
- -
§ The major new features included in this release were the functional programming tools like labda, map, filter, reduce
§ The last version released was 1.6 in 2000
§ Version 2 [Oct 2000]
>
-
-
- -
=
§ Ubuntu
§ Install python3 on using apt installer
§ > sudo apt-get install python3 python3-pip
#asFilm
bello PY
.
r For e makin
(
parsing Python Code
code
bytecode (native executable)
preprocessing code
to asm
Go
§ CPython #t e fastest
§ Pypy
§ Jython
§ InronPython
§ The standard version is called as CPython which is what most of us get when we download from the
-----
official site
-
-- num = 200
- - -
-
-
a
identifier
§ Identifiers
-
--
§ Identifiers or symbols are the names you supply for variables, types, functions, and classes
- - - - - - -
§ Identifier names must differ in spelling and case from any keywords
- - -
§ Keywords
-
-
F
=
--
- . -
None >
-> null -
nothing if 7, 18 :
②§ Operator Keywords: and, or, not, in, is logical operators and or not
E
age
-
---- - = , ,
- 4
-
- - - - -
-
else :
④§ Iteration Keywords: for, while, break, continue, else
- - - - - - - - - -
-
->
-
--
-
S §
O Exception-Handling Keywords: try, except, raise, finally, else, assert
------ -
-
§ Constant and variable names should have a combination of letters in lowercase (a to z) or uppercase (A
-------
§ If you want to create a variable name having two words, use underscore to separate them
-
-
6
-- space
§ Create a name that makes sense (use meaningful names) name :
"Amit"
-- -
pychone
§ Use capital letters possible to declare a constant Pl 3 14 =
.
Java >
- firstName
-- -
-
-
a
name
Name are different
&i st-name or namel
Python is dynamically-typed language
Variable
- -
-
§ It is helpful to think of variables as a container that holds data that can be changed later
-----
§ value = 20 >
-
assigned) variable declaration 0x27
=
inferred Canto IEl
§ name = "steve"
-
--
- -
Eithere
Dum
--
num =
-
-
-
-
-
Salary Hoat 32
I byte : 8 bits
one
max =
28 : 256 - -
Valle =
0-255
-
-
logical address
#Fire
address
-
·t
-
on
↓ (RAND)
- -
primary mem
Start int
>
-
a um = 200
tum right Sh
RUM I "test"
④
Constants
--
-
§ Constants are written in all capital letters and underscores separating the words
--- - -
§ E.g.
§ PI = 3.14
-
- -
§ Naming them in all capital letters is a convention to separate them from variables, however, it does not
-----
- - invalid
statement
§ Instructions that a Python interpreter can execute are called statements Cassignment)
a(n)
- - - - - -
i
- - -
- St
I 20
↑
; Line - NUM
§ Single line statements
/S / -
§ Multi-line statement
--
§ We can make a statement extend over multiple lines with the line continuation character (\)
A
- - - -
§ Line continuation is implied inside parentheses ( ), brackets [ ], and braces { }
int(num)
------
:
§ We can also put multiple statements in a single line using semicolons ** line t = 200
;
- -
S+ 2
Stl ↑
§ Comments
-
mandatory
§ Comments are very important while writing a program
-
Data Types
-
-
Need of Data Types
=
§ Data type is an attribute associated with a piece of data that tells a computer system how to interpret
its value
§ Understanding data types ensures that data is collected in the preferred format and the value of each
property is as expected
§ It helps to know what kind of operations are often performed on a variable
-
-
Ster dynamically
statically tuped
typed - Python ,
C c ++ JS
>
-
,
Python Data Types
Data Types
/ ordered
collection key-value True False
q pairs
-collection
quales
Numeric Dictionary
- -
Boolean -
Sequence Set
numberoes
person : & can-vote : True unordered &
collection
mutable unique
: False q
u
"name"
-
: "PI'
- - is-valid
Integer 3
↑
ahe -
List
Key
immutable
Float Tuple
- -
collection
Comp = 2015 1 qcharacters
Complex -
String
-
+
real
imaginally
Literals 200
A
num =
-
--
°
-
> -
-
num : 300
§ Numeric Literals
- -
-
double
-
1
§ String literals
- --
- -
-
-
single line
§ A string literal is a sequence of characters surrounded by quotes -
> tilinea
- -
Kersors
ie
-
§ A Boolean literal can have any of the two values: True or False
- - - - -
§ Special literal
--
§ Literal Collections
- -
§ Due to the dynamic nature of Python, inferring or checking the type of an object being used is especially
hard
§ This fact makes it hard for developers to understand what exactly is going on in code they haven't
written. As a result they resort to trying to infer the type with around 50% success rate.
§ Why type hints?
§ Helps type checkers: By hinting at what type you want the object to be the type checker can easily detect if, for
instance, you're passing an object with a type that isn't expected
§ Helps with documentation: A third person viewing your code will know what is expected where, ergo, how to use it
without getting them TypeErrors
§ Helps IDEs develop more accurate and robust tools: Development Environments will be better suited at suggesting
appropriate methods when know what type your object is
Type Conversion
§ The process of converting the value of one data type (integer, string, float, etc.) to another data type is
called type conversion
§ Python has two types of type conversion.
§ Implicit Type Conversion
§ Python automatically converts one data type to another data type
§ This process doesn't need any user involvement
§ E.g.
§ result = 10 + 35.50
§ Explicit Type Conversion
§ Users convert the data type of an object to required data type
§ We use the predefined functions like int(), float(), str(), etc to perform explicit type conversion
§ E.g.
§ num_str = str(1024)
Type Conversion
§ Type Conversion is the conversion of object from one data type to another data type
§ Implicit Type Conversion is automatically performed by the Python interpreter
§ Python avoids the loss of data in Implicit Type Conversion
§ Explicit Type Conversion is also called Type Casting, the data types of objects are converted using
predefined functions by the user
§ In Type Casting, loss of data may occur as we enforce the object to a specific data type
Operators
Operators
§ Operators are special symbols in Python that carry out arithmetic or logical computation
§ The value that the operator operates on is called the operand
§ Types
§ Arithmetic operators
§ Comparison operators
§ Logical operators
§ Bitwise operators
§ Special operators
§ Membership operators
Arithmetic Operators
/ Divide left operand by the right one (always results into float) x/y
> Greater than - True if left operand is greater than the right x>y
< Less than - True if left operand is less than the right x<y
-= x -= 5 x=x-5 |= x |= 5 x=x|5
*= x *= 5 x=x*5 ^= x ^= 5 x=x^5
//= x //= 5 x = x // 5
Bitwise operators
is True if the operands are identical (refer to the same object) x is True
True if the operands are not identical (do not refer to the same x is not
is not
object) True
Membership Operators