Python Fundamentals
Python Fundamentals
PROGRAM
• The set of instruction given to the computer in order to perform a specific task is called
the program.
COMPUTER PROGRAMMING
PROGRAMMING LANGUAGE
MACHINE LANGUAGE
COMPILATION
INTERPRETATION
INTERPRETER VS COMPILER
INTERPRETER COMPILER
Translate Program one statement at a time. Scans the entire program and translates it as a
whole into machine code
It takes less amount of time to analyze the It takes large amount of time to analyze the
source code but the overall execution time is source code but the overall execution time is
slower. comparatively faster.
No intermediate object code is generated, Generates intermediate object code which
hence are memory efficient. further requires linking, hence requires more
memory.
Continues translating the program until the It generates the error message only after
first error is met, in which case it stops, hence scanning the whole program. Hence
debugging is easy. debugging is comparatively hard.
Programming language like Python, Ruby use Programming language like C, C++ use
interpreters. compilers.
-----------------------------------------------------------------------------------------------------------------------------
PYTHON INTRODUCTION
• While you may know the Python as a large snake, the name of the Python Programming
language comes from an old BBC television comedy show Monty Python’s flying circus
from the 1970s.
• Van Rossum thought he needed a name that was short, unique, and slightly mysterious,
so he decided to call the language Python.
EASY TO USE
• Python is compact and very easy to use Object Oriented Programming Language with
very simple syntax rules. There is no use of the semicolon or curly-bracket.
• It is a very high-level language and thus very-very programmer friendly.
EXPRESSIVE LANGUAGE
INTERPRETED LANGUAGE
ITS COMPLETENESS
CROSS-PLATFORM LANGUAGE
• Python can run equally well on different platforms such as Windows, Linux, UNIX, and
Macintosh etc. So, we can say that Python is a portable language. It enables
programmers to develop the software for several competing platforms by writing a
program only one.
• Python is freely available for everyone. It is freely available on its official website
www.python.org. The open source means, “Anyone can download its source code
without paying any penny.”
VARIETY OF USAGE/APPLICATIONS
• Python has evolved into a powerful, complete and useful language over these years.
These days Python is being used in many diverse fields/applications. some of which are:
o Scripting
o Game Development
o Database Applications
o Rapid Prototyping
o Web Applications
o GUI Programs
o System Administration
• Python is an interpreted language not a fully compiled one. Fully compiled languages
are faster than their interpreted counterparts.
• So, Python offers faster development times but execution- times are not that fast
compared to some compiled languages.
• Python offers library support for almost all computing programmes, but its library is still
not competent with languages like C, Java, Perl as they have larger collection available.
• Sometimes in some cases, these languages offer better and multiple solutions than
Python.
• Python interpreter is not very strong on catching “Type-Binding” issues. For Example, if
you declare a variable as integer but later store a string value in it. Python won’t
complain to pin-point it.
• Because of its lack of syntax, Python is an easy language to program, But this advantage
has a flip-side too. It becomes a disadvantage when it comes to translating a program
into another programming language.
• This is because most other languages have structured defined syntax.
2. PYTHON FUNDAMENTALS
TOKENS
KEYWORDS
• Keywords in Python are special reserved words that have got predefined meaning and
purposes and can’t be used for anything but those specific purposes.
• We cannot use a keyword as a variable name, function name or any other identifier.
• E.g : int, float, if, else, elif, continue, import etc.
• All the keywords in Python are written in lowercase except True and False.
IDENTIFIERS (NAMES)
• An identifier is a name given to entities like Variables, Objects, Classes, Functions, Lists,
Dictionaries etc.
• Rules for writing identifiers:
o An identifier can be of any length.
o An identifier cannot start with a digit.
o Keywords cannot be used as identifiers.
o We cannot use special symbols.
o Identifiers can be a combination of Letters, Digits, and Underscore.
LITERALS/VALUES
String Literals:
Numeric Literals
• They are immutable and there are three types of numeric literals
o Integer
o Float
o Complex
• Integer: Integers are positive or negative whole numbers with no decimal point. The
Integer literal can be written in,
o Decimal Form - an integer beginning with digits 1-9.
o Binary Form – Integer having only two digits 0 and 1, and beginning with 0b.
o Octal Form - an integer beginning with 0o. (0-7)
o Hexadecimal Form – an integer beginning with 0x. (0-9) (A-F)
• Float: These are real numbers having both integer and fractional parts. ex – 98.5.
• Complex: Complex literal is a way to represent complex numbers. Complex numbers are
numbers that consist of a real part and an imaginary part, where the imaginary part is
represented with a suffix ‘j’ or ‘J’. ex – z=3+4j
Boolean Literals
• Boolean literal is used to represent the two Boolean values , i.e True or False. True
represents the value 1 and False represents the value as 0.
• Python has one special literal which is used to indicate absence of value.
OPERATORS
• These are the signs and symbols that performs certain operations.
• The Parameter on which the operations is performed is called the operands.
• A+B, where + is operator and B is operands.
• Python language many types of operators. They are,
o Arithmetic operators (+, -, *, /, %, **, //)
o Comparison (relational) operators (==, !=, >, <, >=,<=)
o Assignment operators (=)
o Arithmetic assignment operators (+=, -=, *=, /=, %=, **=, //=)
o Logical Operators (Logical AND(and), Logical OR (or), Logical NOT (not))
o Membership operators (in, not in) (in checks if a values exists in a sequence (list,
tuple, dictionary etc) (not in checks if a value does not exist in a sequence
o Identity operators (is, is not) (is checks if the references of two objects are the
same) (is not checks if the references of two objects are not the same)
o Bitwise operators (Bitwise AND (&), Bitwise OR (|), Bitwise XOR (^), Bitwise Not
(~), Left shift (<<), Right shift (>>)
PUNCTUATORS