Unit 1(Python)
Unit 1(Python)
with
‘python’
Python has a simple syntax similar to the English language.
Python works on different platforms(Windows, Mac, Linux, Raspberry
Pi, etc.)
Python has syntax that allows developers to write programs with fewer
lines than some other programming languages.
Python has too much very easy syntax as compared to other
Programming languages.
Python relies on indentation, using whitespaces, to define scope; such
as scope of loops, functions and classes. Other programming languages
often use curly-braces ( { } ) for this purpose.
Unit I:- Introduction &
Syntax of Python
Program
Features of Python
Easy to learn:- Python is a high-level programming language. Every
single statement you use, it proves some similarities to the English
language.
Python Identifiers
Python Keywords
Python Variables
Python data types
Python comments
Python Identifiers
• False, break, del, elif, else, True, except, finally, for, from, if,
import, global, lambda, while, return………etc.
Python variables
1. Single-line comment
2. Multi-line comment
1. Single-line comment :- It comments single line of code. We have
hash(#) symbol as single-line comment .
• Numbers
• String
• List
• Tuple
• Dictionary
1. Python Numbers
• The Number data types are to store numeric values. Python have 4
different types in Numbers.
• int
• long
• float
• complex
int
• A = 45
• B = 1765
• C = -6574
• D = 85756585959757
long
• Stores signed long integers. Internally, they can also represent
Octal or Hexadecimal values.
• A = 746484L
• B = 064D
• C = 0o75648
• D = 93788764673838333
float
• A = 45.78
• B = - 65738.876
• C = 35.2e100
• D = 36464748.9338736
complex
• It consists of an ordered pair of real floating-point numbers
denoted by x + yj, where x and y are real numbers and j is
imaginary unit.
• A = 3.14j
• 3e + 36j
• 34.33e – 36j
2. Python String
• String is a set of characters represent in single or double quotes. Python
allows 3 operators to work for a String.
I. The Slicing Operator ( [:] ):- Based on index number it retrieves substring.
Python allows backward string index where last character of String has
index -1, second last at -2 and so on.
II. The string Concatenation Operator ( + ):- It joins Strings.
III. The repetition operator ( * ):- repeat the left operand string according to
right operand numeric value.
Example:- Output:-
• The list are most used datatype that are represented in square
braces [ ]. It looks similar like Array. But it is not. Array is static
and list is dynamic in size. Array has fixed datatype for all
elements, whereas list has no datatype bounding.
• A List also allows all 3 Operators like String.