Copy of L-1 Pyhton- Basic Fundamentals
Copy of L-1 Pyhton- Basic Fundamentals
Outline
Recall Memory
Python
Comments
Indentation
Token
Identifiers
Keywords
Constants
Variables
Literals
Operators and its
types
precedence of
operators
data types
PYHTON
i
INDENTATI
ON
Indentation refers to the spaces at the beginning of a code line.
COMMENT
S
They are added with the purpose of making the source code easier for humans to
understand, and are ignored by Python interpreter.
Python supports single-line (or end-of-line) and multi-line (block) comments.
1) Single Line Comments - It should be start with #
# This is a comment.
2) Multi-Line Comments - Python does not provide a direct way to
comment multiple line. You can comment multiple lines as follows −
# This is a comment.
# This is a comment, too.
Following triple-quoted string is also ignored by Python interpreter and can be used as a
multiline comments: '''
TOKEN
The smallest part of the statement is a token. It may be characters, digits, special symbols
and punctuations.
a=18
Tokens are a, = and
KEYWOR
Keywords are special words , which convey some special meaning to the compiler.
Keywords are as follows
False await else import pass
IDENTIFIE
RS
It is the name given to the such as variable, function, list, dictionary etc
VARIABL
Creating Variables
● A variable name must start with a letter or the underscore character
● A variable name cannot start with a number or any special character like $, (, * %
etc.
● A variable name can only contain alpha-numeric characters and underscores (A-z,
0-9, and _ )
● Python variable names are case-sensitive which means Name and NAME are two
different variables in Python.
● Python reserved keywords cannot be used naming the variable.
x=89;
y=”aman”
x, y, z = "Orange",
"Banana", "Cherry"
print(x)
print(y)
One Value to Multiple Variables: And you can assign the same value to multiple
variables in one line:
x=y=z
=
"Orange"
print(x)
print(y)
LITERAL
S
Literals is a value assigned to variables while programming.We mainly have five types of
literals which includes
1. string literals - The group of characters in single, double or triple quotes.
s= 'Scaler Academy' #
single quotes
d="Hello World" #
double quotes
e="""Welcome #
Triple quotes
to
Scaler
2. numeric literals - Numerical literals in Python are those literals that contain digits
only
● Integer: The numerical literals that are zero, positive or negative natural numbers
and contain no decimal points are integers.
● Float: Unlike integers, these contain decimal points.
● Complex: Complex literals are represented by A+Bj. Over here, A is the real part.
And the entire B part, along with j, is the imaginary or complex part
A = 67 #integer
literal
B = 3.5 #float
OPERA
x = True TORS
Y = False
Operators are used to perform operations on variables and values.Different operators are as
follows
● Arithmetic operators-
● Assignment operators
Operator Description Syntax
< Less than: True if the left operand is less than the right x < y
and Returns True if both statements are true x < 5 and x < 10
DATA
TYPES
Python Data Types are used to define the type of a variable. It defines what type of data
we are going to store in a variable.
python has various data types
1. Numeric
2. String
3. List
4. Tuple
5. Dictionary
1. Numeric Data Type- The variable stores numeric value.
a=23 # integer
data
b=2.34 # float
data
2. String Data Type - The variable stores sequence of characters which are enclosed by ‘ ‘, “ “
or ‘’’ ‘’’
x = “hello”
3.Lists: List is also a sequence of values of any type. Values in the list are called
elements / items. These are mutable and indexed/ordered. List is enclosed in square
brackets.
x = [1, ‘a’,
4. Tuples: Tuple is also a sequence of values of any type. Values in the tuple are called
elements / items. These are immutable and indexed/ordered. Tuple is enclosed in round
brackets.
T = ('spam',
5.Dictionaries: These can store any number of python objects. What they store is a key
– value pairs, which are accessed using key. Dictionary is enclosed in curly brackets.
Immutable Types: The immutable types are those that can never change their
value in place. Integers, Floating Point Numbers, Booleans, Strings and Tuples are
immutable types
Mutable Types: The mutable types are those that can change their value in
place. Lists, Dictionaries and Sets are mutable types
type( ): The data type of a constant or variable can be displayed using type( ) statement with
the required argument.
x=10
id(x)
1722770
input (): This function first takes the input from the user and converts it into a string.
Syntax:
Variable name = input('STATEMENT')
Example:
There are various function that are used to take as desired input few of them are : –
● int(input())
● float(input())
Number of boys: 5
Number of girls: 6