Python Lesson One
Python Lesson One
Python
Lesson-1
Basics of Python
By
Prof. Dr. A.B.Chowdhury,HOD,CA
value.
2 If the code point is ≥ 128, it’s turned into a sequence of two, three,
or four bytes, where each byte of the sequence is between 128 and
255. UTF-8 has several convenient properties as stated below:
By Prof. Dr. A.B.Chowdhury,HOD,CA (TIU,W.B.)
The tools and techniques of programming in Python Lesson-1Basics
September 30,of
2024
Python 18 / 46
Introductory Ideas of Python–Literals-Contd.
1 It can handle any Unicode code point.
2 A Unicode string is turned into a sequence of bytes that contains embedded
zero bytes only where they represent the null character (U+0000). This
means that UTF-8 strings can be processed by C functions such as strcpy()
and sent through protocols that can’t handle zero bytes for anything other
than end-of-string markers.
3 A string of ASCII text is also valid UTF-8 text.
4 UTF-8 is fairly compact; the majority of commonly used characters can be
represented with one or two bytes.
5 If bytes are corrupted or lost, it’s possible to determine the start of the next
UTF-8-encoded code point and resynchronize. It’s also unlikely that random
8-bit data will look like valid UTF-8.
6 UTF-8 is a byte oriented encoding. The encoding specifies that each
character is represented by a specific sequence of one or more bytes. This
avoids the byte-ordering issues that can occur with integer and word
oriented encodings, like UTF-16 and UTF-32, where the sequence of bytes
varies depending on the hardware on which the string was encoded.
By Prof. Dr. A.B.Chowdhury,HOD,CA (TIU,W.B.)
The tools and techniques of programming in Python Lesson-1Basics
September 30,of
2024
Python 19 / 46
Introductory Ideas of Python–Operators-Contd.
Since Python 3.0, the language’s str type contains Unicode characters, meaning
any string created using ”unicode rocks!”, ’unicode rocks!’, or the triple-quoted
string syntax is stored as Unicode.The default encoding for Python source code is
UTF-8, so we can simply include a Unicode character in a string literal.
Python operators.
An operator is a symbol or a combination of symbols that indicates an operation to
be performed upon one or more variables, constants or literals to generate some re-
sult. Three types of operators are usually supported by all programming languages.
They are:
Arithmetic operators for calculations,
Relational operators for comparisons and
Logical operators for basic logical operations of And, Or and Not.
Python supports six different types of operators. In addition to the three mentioned
above, the other operators are:
Bitwise operators
Membership operators and
Identity operators
By Prof. Dr. A.B.Chowdhury,HOD,CA (TIU,W.B.)
The tools and techniques of programming in Python Lesson-1Basics
September 30,of
2024
Python 20 / 46
Introductory Ideas of Python–Operators-Contd.
We shall now study each type operator in detail.
Arithmetic Operators.
The following table illustrates the arithmetic operators available in Python.
Operator Name Functional Example
+ Addition (i) 2+3 yields 5 (ii)+7 implies positive seven
- Minus or Subtraction (i) 5-3 yields 2(ii)-8 implies negative eight
* Multiplication 5*3 yields 15
/ Division 10/4 yields 2.5
% Modulus or Modulo operator 5%2 yields 1
** Exponent 2**3 returns 8
// Floor division 5//2 returns 2
The following table shows different Python Operators in order of the prece-
dence from the highest to the lowest:
Operator Name
** the binary operator for exponentiation
, + ,- Complement, unary plus and minus (method names for the last two are +@ and -@)
*, / ,% , // Assignment, division,Modulo and integer division operator
+, - the binary addition and subtraction operators
>>, << The Shift operators
& Bitwise ’AND’
ˆ, | Bitwise exclusive ‘OR’ and regular ‘OR’
<=, <, >, >= the relational operators
<>, ==, != the relational operators for testing equality
=, %=, /=, //=, -=, +=, *=, **= the assignment operators
in, not in membership operators
not, or, and logical operators
The symbol >>>represents the default prompt of the Python IDLE shell
where IDLE stands for Integrated Development and Learning Environment.
Python can also be loaded without the IDLE by loading the file shown
as Python 3.12(64-bit) when the console is shown as depicted below for
running python as a scripting language.