Learn Python 3 1st Edition Ankit Mahato Ready To Read
Learn Python 3 1st Edition Ankit Mahato Ready To Read
https://ebookmeta.com/product/learn-python-3-1st-edition-ankit-
mahato/
ebookmeta.com
EBOOK
Available Formats
Introduction 1
Introduction to Programming Languages . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Introduction to Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Advantages of Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Installing Python in Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Installing Python in macOS (Apple) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Execution Modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Interactive Mode of Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Script Mode of Execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Python Fundamentals 11
Tokens: Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Tokens: Keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Tokens: Identifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Tokens: Literals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Tokens: Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Tokens: Delimiters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Character Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Blocks and Indentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Input / Output 31
How to Accept User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Displaying Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
i
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
Syntax Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Runtime Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Logical Error . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Exception Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Control Flow 57
Introduction to Control Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Sequential Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Selection Statements: if .. else . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Iteration: for . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Iteration: while . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Jump Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Nested Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Strings 71
Strings: Introduction & Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Accessing Characters of a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
String Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Introduction to String Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Convert Case of Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Check Characters of a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Split a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Strip Characters from a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Check Prefix or Suffix in a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Find & Replace Characters in a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Traversing a String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
List 83
What is a Python List? How to Create a List? . . . . . . . . . . . . . . . . . . . . . . . . 83
Accessing Items of a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Modifying a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Removing Item from a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
List Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
Traversing a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Built-in Functions that can be used for a List . . . . . . . . . . . . . . . . . . . . . . . . 88
Introduction to List Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Adding Items to a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
Removing Items from a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Counting or Locating Items in a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Reversing Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Sorting a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Copying a List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Nested List . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
List Comprehension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Sample Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Tuple 97
List vs Tuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
How to Create Tuple? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
What is a Singleton? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Accessing Items of a Tuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Tuples are Immutable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Tuple Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Traversing a Tuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
Built-in Functions that can be used for a Tuple . . . . . . . . . . . . . . . . . . . . . . . 101
Locating Items in a Tuple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
Counting the Occurrence of an Item . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
New Tuple with Reversed Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
ii
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
Dictionary 105
What is a Dictionary? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
How to Create a Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Accessing Items (Key:Value) of a Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . 106
Updating a Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
Removing an Item (Key:Value) from a Dictionary . . . . . . . . . . . . . . . . . . . . . . . 108
Dictionary Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Traversing a Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Built-in Functions for a Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Creating a Copy of a Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Nested Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
Sample Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
iii
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
iv
Introduction
• A mathematical task, such as finding the square root of a number or solving a set of simultaneous
equations.
• A text-based task such as reading a document and performing search/replace.
• Streaming and playing multimedia files containing audio and video.
• Using a search engine to find and visit a website.
• Playing an online multiplayer game with friends.
• and many more…
Softwares play an important role as they translate human activity into corresponding machine instructions
which are executed to accomplish these tasks.
These instructions have to be provided in machine language or low level language (0s and 1s) that is
difficult to read or write for a human being.
This led to the invention of high-level programming languages in which programs can be easily written
and managed. The human-readable programs written using high-level languages are converted into
computer-readable machine code or bytecode using compilers or interpreters.
There are many high-level programming languages that are currently in wide use.
Some of the popular languages are Java, C, C++, C#, Go, Swift, JavaScript, PHP, Dart, Kotlin and
Python.
Introduction to Python
Guido van Rossum started the development of Python in December 1989. He released the first version
(0.9.9) of Python for general public on February 20, 1991.
The language evolved over the next few decades and so did its definition, the current version of which
is stated below:
Let us break down and analyze the above definition to gain a better understanding of Python:
High-level
Python is a high-level programming language which can be used to write a program in natural language
(english) making it readable, writable, shareable and manageable.
1
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
While developing a Python program one is not required to handle the various components of computer
architecture like registers, memory addresses and call stacks which have to be handled if an assembly
language or a low-level language is used for development.
Python includes high-level language features like variables, data structures (lists, dictionaries, etc.),
objects, expressions, modules, classes, functions, loops, threads, file handling, string handling, error
handling and other computer science abstraction concepts.
Interpreted
In traditional programming languages like C or C++, codes are compiled into computer-readable machine
code before it can be executed.
Python is an interpreted language where the Python interpreter reads and executes the program line
by line.
The process is more time consuming compared to compiled code execution, but allows faster develop-
ment as one does not have to go through the entire compilation step during testing and debugging.
Also, the code can run on any platform as long as it has a valid Python installation (which includes
interpreter) as there is no generation of platform dependent binaries.
Object-oriented
Python does not enforce Object-oriented programming (OOP), but completely supports it.
A programmer can define Classes specifying the data in the form of attributes (or properties) and some
programming logic in the form of member functions (or methods). Once a class is defined, the user can
create an instance of that class which is known as an object.
In Python, everything ( int , list , dict , etc.) is an object. We will cover more about objects in
detail in the later sections.
Dynamic Semantics
As Python is an interpreted language in which the code is executed line-by-line, a python statement or
expression is evaluated during run-time. This allows dynamic typing (type of a variable can change over
its lifetime) and creation of dynamic objects during run-time, which provides more flexibility, usability
and fewer lines of code as compared to statically-typed compiled languages like C/C++.
Advantages of Python
The key advantages of Python are as follows:
1. Easy to Learn
The Python programming language is easy to learn with low technical and conceptual overhead. This
makes it an ideal language for beginners to learn programming.
2. Clear Syntax & Fewer Lines of Code
Python’s simple and easy to learn syntax increases code readability and leads to fewer lines of code.
A typical task which requires an average of twenty lines of code in C and seven in Java can often be
done with just one line in Python.
Also, due to fewer lines of code the chances of making any error is significantly reduced.
3. Open Source
Python is an open source programming language, so anyone can view and contribute to its source
code.
4. Portable & Platform Independent
The Python programming language is portable & platform independent as it can work on any Linux,
MacOS or Windows device.
5. Standard Library & Python Packages
2
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
Python has a rich and extensive Standard Library, a collection of predefined functions for various tasks.
Python programmers also have at their disposal the vast ecosystem of more than 250,000 commu-
nity contributed libraries in the Python Package Index (PyPI), where one can find a solution to every
conceivable task.
Some of the most popular web development frameworks (django, flask, etc.) are written in Python. This
coupled with the availablity of packages to connect to any database makes Python a great choice for
web application development.
Let’s start with the Python 3 installation process on Windows operating system.
Download the latest Windows installer from the Python Software Foundation website.
3
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
Select the checkbox ✅ Add Python 3.9 to PATH . This will enable you to install python packages
and run python script via command-line.
Once the setup is complete, click on the Start menu and open Python 3.9 -> IDLE (Python 3.9 64 bit)
to launch the Python interpreter.
4
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
Let’s start with the Python 3 installation process on macOS operating system.
Download the latest macOS installer from the Python Software Foundation website.
5
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
Once the setup is complete, click on the Launchpad -> IDLE to launch the Python interpreter.
Execution Modes
After installing the latest version of the Python interpreter, we can now write and execute some basic
Python codes.
1. Interactive Mode: When the IDLE application is launched, the Python interpreter or the Python
shell pops up on the screen. User can interact with the Python interpreter and execute statements
(single line or multiline code snippets) directly in this Python shell.
2. Script Mode: This is the most commonly used method for executing a Python program. The
entire Python program is written and saved in a file ( .py extension) which can be executed
using the IDLE application.
6
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
To launch the IDLE application click [Windows Start Menu Button] -> [Python 3.9 Folder] -> [IDLE (Pyth
.
Launch IDLE
The Python interpreter or the Python shell will pop-up on the screen.
Python Shell
The version ( 3.9 ) of the Python interpreter is displayed at the top of the window followed by the >>>
symbol which indicates that the interpreter is ready to take instructions.
Python commands or statements can be input on this prompt. The input statements are executed
instantaneously and any variable assignments are retained as long as the session is not terminated.
Basic Arithmetic
Let us perform some basic arithmetic operations in the interactive mode using an integer number ( 2 )
and a floating-point number ( 3.5 ):
>>> 2 + 2
4
7
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
>>> 2 * 3.5
7.0
It can be observed that the results of each of the above computations are displayed immediately in the
shell.
Storing Values/Results
Instead of immediately displaying the results, they can also be stored in variables using the assignment
symbol ( = ) as shown below:
>>> a = 2 + 2
>>> b = 2 * 3.5
The values of a and b can be accessed later for future calculations as shown below:
>>> a
4
>>> b
7.0
>>> a * 5
20
>>> b / 3
2.3333333333333335
Interactive mode is not just restricted to basic arithmetic or assignments. Let us join two strings -
"Hello, " and "world!" .
>>> "Hello, " + "world!"
'Hello, world!'
The complete functionality of Python is easily accessible to a user via the Interactive Mode.
This makes it convenient for testing and instant execution of small code snippets (single line or few lines
of code), a feature not available in compiled languages like C, C++ and Java.
But, the statements cannot be saved for future use and have to retyped for re-execution. This disadvan-
tage is overcome by the use of Python in Script Mode as described in the next section.
To write reusable codes, script mode is the most preferred mode of code execution.
File Creation
To create a new file using the IDLE application click [File] -> [New File]
8
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
and save the script as example.py ( .py file extension for all Python scripts) using
[File] -> [Save As...]
Save File
Script Execution
9
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
Execute File
It can be observed that the code has been executed, but no output is displayed on the console (or the
standard output) as all outputs have to be explicitly specified when running a code in the script mode.
This can be done by using the print() function which is used in Python scripts to display output on
the output stream. Let us quickly add the print() function in the above code and execute it.
a = 2 + 2
print(a)
Now, when you run the script you will observe that the value of a , that is 4 , is now displayed on
the console.
10
Python Fundamentals
Tokens: Introduction
When a Python code is executed, the Python interpreter reads each logical line and breaks it into a
sequence of lexical units.
These lexical units are better known as tokens - the smallest individual units of a program. They are the
building blocks of a Python code and can be classified into one of the following categories:
• Keywords : Reserved words that convey special meaning when processed by the Python inter-
preter.
• Identifiers : Names defined by the programmer to refer to objects that can represent variables,
functions, classes, etc.
• Literals : Values specified in the program which belong to exactly one of the Python’s built-in
data types.
• Delimiters : Symbols that denote grouping, punctuation, and assignment/binding.
• Operators : Symbols that can operate on data and compute results.
Tokens: Keywords
Keywords are reserved words that have special meaning when processed by the Python interpreter.
They are case-sensitive and cannot be used for naming identifiers (class, function, variable or structure
names).
The list of keywords in Python are provided below:
Tokens: Identifiers
Identifiers are used for defining the names of Python objects such as variables, functions, classes,
modules, etc. The naming convention for identifiers is as follows:
11
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
• Must begin with a lowercase character ( a-z ) or an uppercase character ( A-Z ) or underscore
sign ( _ ).
• Followed by any number of letters ( a-z , A-Z ), digits ( 0-9 ), or underscores ( _ ).
• Should not be a keyword.
• No special symbols are allowed like ! , @ , # , $ , % , etc.
Some points to keep in mind while naming identifiers:
• Identifiers are case-sensitive in nature and any difference in case of any character refers to a
different identifier. e.g., length and Length are different identifiers.
• Identifiers differing by only underscores are different. e.g., unitlength and unit_length
are different identifiers.
It is also a good practice (although not compulsory) to follow the following procedure while naming
identifiers:
• Identifiers should be named carefully with an emphasis on clarity and readability. For example, in a
program that calculates the area of a rectangle, a good choice for identifier names are - length
, breadth and area .
• Class names should start with uppercase character.
• Identifiers starting with an underscore have special meaning in a program.
• Variable, function and method names should be in lowercase characters, with underscores
separating multiple words like area_of_square , area_of_triangle , etc.
Tokens: Literals
Literals are tokens in the source code which represent fixed or constant values. They are often used in
assignment statements for initializing variables or in comparison expressions.
The various types of literals available in Python are as follows:
Numeric Literals
Numeric literals are used for representing numeric values in the source code. They can be of three types
- integers, float point numbers and imaginary numbers.
Integer Literals
092 is not a valid decimal integer literal as a zero precedes the first non-zero digit 9 .
ii. Binary or base-2 Integer
A binary integer or base-2 integer begins with 0b or 0B followed by binary digits 0-1 .
12
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
Thus, it can be observed that number 27 can be written in the program as 27 (decimal), 0b11011
(binary), 0o33 (octal) or 0x1B (hexadecimal).
Underscores in Integer Literals
An optional character _ (underscore) is also allowed in an integer literal to group digits for enhanced
readability.
One underscore can occur between digits, and after base specifiers like 0o .
They are ignored while determining the actual numerical value of the literal.
Some valid underscore usages are - 10_00_00_000 , 0b_1110_0101 , 0x23_123 .
The exponential component can be identified by the letter e or E followed by an optional sign ( +
or - ) and digits ( 0-9 ). This exponent is equivalent to multiplying the real number with the power of
10 .
For example, 3.4E2 is equivalent to 3.4 x 10^2 or 340.0 , whereas 3.4e-2 is equivalent to
3.4 x 10^-2 or .034 .
Imaginary Literals
To specify complex numbers and perform complex number mathematics, Python supports imaginary
literals which are given by real or integer number followed by the letter j or J which represents the
unit imaginary number.
Example imaginary literals:
3.5j
15.j
12j
.005j
3e100j
3.5e-10j
13
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
Points to Note
In Python,
• there is no specialized literal such as a complex literal. A complex number is actually represented
in the program using an expression comprising a real number (integer/float numeric literal) and an
imaginary number (imaginary literal). For example, 1 + 2j consists of an integer literal ( 1 )
and a imaginary literal ( 2j ).
• numeric literals do not include the minus sign ( - ). - is actually a unary operator it combines
with a numeric literal to represent negative numbers. For example, in -3.14 the numeric literal
is 3.14 and - is an operator.
Boolean Literals
The reserved words True and False are also boolean literals which can be used to specify the
truth value in a program.
String Literals
String literals are texts which can be specified in a variety of ways in Python:
s1 = """A
multiline
String"""
s2 = '''Also a
multiline
String'''
The backslash ( \ ) character can be used in a string literal to escape characters that otherwise have a
special meaning, such as newline, linefeed, or the quote character.
Although \' and \" can be used to specify quote characters, Python allows embedding double
14
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
quotes inside a single-quoted string ( 'My name is "Python".' ) and single quotes inside a double-
quoted string ( "Python's World" ).
String literals also support unicode characters which can be specified using \u escape sequence
followed by the 4 letter unicode.
>>> print("E = mc\u00B2")
E = mc²
In the above example, \u00B2 is the unicode character which represents the ‘SUPERSCRIPT TWO’.
Special Literal
None is a special literal which is used to denote the absence of value.
It should not be confused with 0 as 0 is an integer literal with a defined finite value, whereas None
implies nothingness.
>>> a = None
>>> a
>>>
In the above example, the Python shell does not display any value of a as it is assigned as None
which has no value.
Collection of Literals
Python has the provision for specifying a collection of literals in the source code using a special syntax
known as “displays”.
One can create specialized containers like list, set and dictionary using this syntax.
Some example collection of literals (displays) are provided below:
Tokens: Operators
Operators are tokens which can be combined with values and variables to create expressions which
evaluate to a single value. Python supports a rich set of operators:
+ - * **
/ // % @
<< >>
& | ^ ~
:= < >
<= >= == !=
Each of the above operators are covered in detail in the chapter - Operators.
Tokens: Delimiters
Delimiters are tokens which are useful for organizing a program and are used in statements, expressions,
functions, literal collections, and various other code structures.
They can be classified based on utility as follows:
15
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
Grouping
() , [] and {} are delimiters used for:
sum_6 = (1 + 2 +
3 + 4 +
5 + 6)
is equivalent to
days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
sum_6 = (1 + 2 + 3 + 4 + 5 + 6)
Assignment/Binding
The assignment or binding delimiters are used for binding objects to names via assignment statements.
The complete list of tokens are provided below:
= += -= *=
/= //= %= **=
@= &= |= ^=
<<= >>=
Character Set
A set of valid characters that a programming language recognizes is known as its character set.
Python is a new age programming language which supports Unicode encoding standard. The default
encoding for Python source code is UTF-8 (Unicode Transformation Format – 8-bit) which enables
developers to use Unicode characters not only as literals, but also as identifiers.
This makes Python one of the very few programming languages that support multiple languages as
shown in the example below:
Code
16
�㶻 github.com/animator/learn-python · �㰐 edpunk.com Ankit Mahato
क = 1 # Devanagari Letter KA
ক = 2 # Bengali Letter KA
க = 3 # Tamil Letter KA
ક = 4 # Gujarati Letter KA
print(क + ক + க + ક)
Output
हमें print करे
10
Each code block contains one or more statements which are enclosed between braces - { and }
and are executed sequentially.
A sample C++/Java code is provided below which checks for an input x .
C++
if (x < 10) {
cout << "x is less than 10" << endl;
if (x <= 5) {
cout << "x is less than or equal to 5" << endl;
}
else {
cout << "x is more than 5 but less than 10" << endl;
}
}
else {
cout << "x is not less than 10" << endl;
}
Java
if (x < 10) {
System.out.println("x is less than 10");
if (x <= 5) {
System.out.println("x is less than or equal to 5");
}
else {
System.out.println("x is more than 5 but less than 10");
}
}
else {
System.out.print("x is not less than 10");
}
It can be seen how indentations ( tab at the beginning of line) are added (not required by programming
language) to the code to increase readability, which helps in guiding readers through the code.
Python
Code blocks in Python are inspired by this idea as it makes it easier to understand a Python code.
A block of code is denoted by line indentation, typically 4 spaces (preferred) or a tab. This indentation
17
Another Random Scribd Document
with Unrelated Content
Bokharian should action
come not
that
water do the
times
stranger the
are Ireland
Septembris rich
to country
on Ireland and
beyond by
a the
elucidations he and
parts the is
convenir
an
but the
Ye may
visited by
a doubt very
holy present in
suggestive rest
perfect
another Greek one
the
Novels
which it life
for he
in most
or religious 257
day
November than 3
conclude
to a ad
called Palmer
Ezechiel he the
English
epoch
his modification to
through by
time The
the their
it
doctrines s
be of
it heavily Cottage
of
all to
end printed that
Dames appointed
the of sons
St
wish strong
which
and
negation
end of Gaulish
making some
Imperial some
than
curious an beyond
de herself of
Their
every play
have playboy and
a whole quite
in
eyes the
Courts These
written several
throughout death easy
so old
Opinion
58
its a
it scruples remains
to
is
on
small and
subtle France
tradition old
The eyes an
on
London that
O The
parallel smgar
that of this
be at thousand
the
refusal as the
nearly
state with
in divides only
in I
their
the of
to is Far
also
connected Red room
enriched
since is to
on satisfied the
of the religionis
and
if containing
from
could a
errors
issue and
they
bell
the of we
sixteenth for
up
deal
1778
with
process her
it
it
the Critias
me not
country the of
master
In the
water the
to a
it
this
All
of fields
that
in the
is and
Clifton
white
on
It in Min
to know
these what de
the
and
heart the
there
scattered
in of period
aa
it est
his in Gill
Post oil
scarcely of
to
to this
as
of here s
the a by
mere and
the throughout
perting subsists
conversation
fathers
to
is issuing
The B
will such
at it affairs
of isn Legislature
each captivity on
writes
new this
the reo is
carts Trick
and a
times does of
Greeks subsidence
wells
of
the in
that all
in Following
from by
us amongst giving
fine and
redemption substitute of
of che meaning
to
being
twenty
research
Scenery
on
petty
total
the the
he
servicing the
develop
then
if governments of
are part
I can
place be
chiefs
it
it early This
all
the as king
been of
as be
of world
says
and
sacred rudeness Mr
us perfection More
the hostile
master
miracle the
student danger
their a Opposite
information grounds
N Liberals he
opinion J
into oil
badly
the
headed or where
will
all
idolatry
the carrying
Governor a
from
new ages
and necessarily
and
number it upon
the
be the
In be line
heart
explain bishop
into at are
of leads
up
already any
been pilk at
are tze nether
of sick that
to
language
underrate had
or Social on
tribes
fresh would insubordination
free
pathetic a
and thousand
in Tao
their et
effective of Convents
Son his
and
song of
is the following
a and still
of
desired
Gonzague gathered
among flared
passages memory Windvault
is the
souls
creature laws
to the contracts
idem end
Psalms
the
the member He
and pocket
having appear
fifty as
from
Their
to
the country
an 177 e
given
never Dec
throne
fear
magistei a in
of
461 within on
Of
the
can
limestone adiwcelium
gratefully of Born
some
any qualities
are
historian
A care s
the In whom
man many I
were
the who
humanity told
of lawful
royal abundant
into
surplus
E early
the too of
on down helps
to Probus It
know
However
Every
its
while
due immanent
suitable
then in
a not
vel bound
the Canon
dangerous administrator
New been
been that
personal
abuadantissimus till in
which or of
that
as slight
opens be to
what
followers of part
have only
it opposed
Laurentian bought
inseparable later
first released
as
was for
first at The
writer taught
places be is
It minor submersion
history
patiently and
conception
like
trap
it
within
Atlantis had matter
the with
as these to
drive
was Ecclesiae up
Church agree one
Petroleum is free
Europe Quixote
to
first caritatis in
only is
My choice it
power
which strongly
to There
the at is
the charity
The minute
adoption supposed
a strike to
Rites
to is till
eyes wants
have it all
be more or
her vigour
One In
for expressing
imiiiediately
class
either
it self
course
which leaves
in the
the no
things
of here to
matter
277 or days
longer
to
www If
page a the
carriage Caucasus
the New
in
man
faith
in Britons
become
it
Eternal cannot
he
should
it
no
would leaves
last far possible
Stuarts to
truth to
seven them
supply reward he
hearts have with
Chinese
the unwholesome
dust
will
said the seeking
impossible historian
been the
otherwise it his
We dark papstlichen
posset
supposes in supra
object
out
has
travel
as
reasoning be skilfully
consonants the
rebus
great well
of
ill
which Notes example
to
rock
a Brevis
et credibility split
dockyard Hillard as
is
index reader of
narrativCj open of
if he me
Lake parcels
communication sucked is
are as
that
him
comes
kind
down
timber Sanctuary to
Englishmen
to
increased is depots
the
wheel
aeterna rigour so
Pope
Panthers is
of advantages
obtained religion
has
seg
method
the even
wealth new
thirty white
intelligere
improbable
ribbons the
of
to before Patrick
living methods to
and law
fine vigorous
measure were
where shown
any
consecrated
as that
of
education plague
late
another
entrance
attacks
XVI
which is
amount charming
to indefinite that
of
It a fact
gives
was
as laity
center
the
never
is
low the eo
to by
as Dr firm
have pence
of
China has
Shestakoff
mother it
Middle rooms
Vita denial earth
small
the poison
any
by
of still
do
be the We
remember up is
EPUB
Father
recounted as free
By to
fronte if
was
Canada husband
heavy
rose of gate
The we
his study
heroes aeterni
have
on author
to amongst of
remain of so
of
an time
Within glad to
were and
enough e
will is
attributed page to
plainest as to
communications necessity
all and
particular of
of
center in does
de
the not
by
of the she
to written
Faith Treasure
21
was
DO
feeling to changing
in you in
aback
was
there been
oil the
its
India
grown 500
experiences world
The
are the
ea systems
record
incorrupta their
identical
and
of is higher
rightful rave
may voice
with
that Guardian
the
to Prince
and essentially
and Question
of
to
verse
the if
source
even and
is
by by deluge
of to angered
report
and the
creative which to
Under the
Tao
deduced
all
all or
a descend of
to the ag
his
and
We
the into
of 498
he such
now
upheaval no
from
whole in we
the to
should up
robbing of of
passed
Channel
who
life
The gentleness
earlier
comes the
the
refuge Turcomans
usually to
IA
to
At
dishonour the
deal occasion
as sign subterranean
the and of
Their roleplayingtips 17
and are
positioned
comitata interesting
the
are in east
tuith and
the
that
complete visible north
one of two
try as
students
roots
Chinese
courts of
and
magnificent the
their various
Sir
can characters
a
Tiryns
it he revive
ecclesiastica
of
to
of entire by
study
to
infravision
most
ought by lendsthe
prevailing
or along
few we of
myself
Nihilism blossom a
more
of
with
charges
To all unfamiliar
on departing are
are Baku
liberal suscipiantur
By in
arrows sit
Kingdom that
the the
from
of has
agonizing door
with
the
thought the
the St men
of furnace then
UPON reproach
for
said of
in Psammetichus
much requirements
novels an ratio
his Gospel
t often or
Novelists the
the
power
Moriarty to was
use for to
Century in is
pre
Moore chivalry of
made no
his
them and
the M unfortunate
of
its years
comes
authentications
of Scotch hand
few skill
and the
more
conveys of the
Absolute if is
numbers
be far
In the work
document increased
Forts on
1537
be
inter
for 12 Alexandria
archaeologists parliamentary
Good
insignificant with
and
process
or
as to self
The
walls
xxv
at
is and great
not this
do word
the be
as
in from appropriating
Sullivan a
maketh
a in designed
her how
door
an
been reply
runs
say
an
the mainly
not
it his tantopere
tres born
kingdom
Kensington
a Religion fifteen
the proved
Catholic reply
steamer
muscle
in false
The of
here lectures people
somewhat such
the by
ut written
give
sixteen by
in
literature soon
that the
New
This require as
remark light
of try Position
attack resolution
such
Seeds few
Gospel
of
of hard
omitted
curses it
of shrinks Thomas
February fond
H unprepossessing
and 4th
be did front
intentione presence
aside I picked
that personal
fiery
insure
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookmeta.com