

















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















































































Presented by
Mohd Shuaib
Assistant Professor
return).
Example: 4 statements in 4 separate lines
print('SNo: ', 1)
print('First Name: ', 'Aditya')
print('Last Name: ', 'Joshi')
print('Age: ', 19)
the semicolon ; is used to separate multiple statements in a
single line.
Example:
print('Hello');print('BCA class!');print('how are you’)
Expressions in parentheses (), square brackets [ ], or curly
braces { } can be spread over multiple lines without using .
Example:
list = [10, 20, 30, 40,
Indentation in Python
Leading space or tab at the beginning of the line is considered
as indentation level of the line, which is used to determine the
group of statements. Statements with the same level of
indentation considered as a group or block.
For example, functions, classes, or loops in Python contains a
block of statements to be executed.
C# or Java use curly braces { } to denote a block of code.
Python uses indentation (a space or a tab) to denote a block of
statements.
Example: demonstration of if else blocks
if 10 > 5: # 1st block starts
print("10 is greater than 5") # 1st block
print("Now checking 20 > 10") # 1st block
if 20 > 10: # 1st block
print("20 is greater than 10") # inner block
else: # 2nd block starts
print("10 is less than 5") # 2nd block
print("This will never print") # 2nd block
Function contains a block with 2 statements
def welcomemsg(msg):
print("Hello ", msg)
print("Welcome to Python class BCA Stuents")
You may use either interactive shell or IDLE or any GUI based
Error will be
IndentationError: expected an indented block if you not use
indentation or IndentationError: unexpected indent
multi line string
Python multi-line comment is a piece of text enclosed in a delimiter (“””)
on each end of the comment. Again there should be no white space
between delimiters (“””). Single or double quotes both may be used
""" Multi-line comment used
print("Python Comments") """
print("Hello Class")
function or class signature, then these turn into docstrings.
associate documentation that has been written with Python
modules, functions, classes and methods. It is added right below
the functions, modules, or classes to describe what they do. In
Python, the docstring is then made available via the doc
attribute.
def add(a, b):
"""adds the value of a and b"""
return a+b
print(add.doc)
print(add(2, 10))
Identifiers in Python are case sensitive, which means variables
named age and Age are different.
Class names should use the TitleCase convention. It should
begin with an uppercase alphabet letter e.g. MyClass, Student,
Employee.
Function names should be in lowercase. Multiple words should
be separated by underscores, e.g. add(num),
calculate_tax(amount).
Variable names in the function should be in lowercase e.g., x,
num, salary.
Module and package names should be in lowercase e.g.,
mymodule, tax_calculation. Use underscores to improve
readability.
Constant variable names should be in uppercase e.g., RATE,
Display Output
of any Python expression on the Python shell.
by comma.
The following example displays values of name and age variables using the
single print() function.
name="Aditya"
print(name) # display single variable
age=
print(name, age)# display multiple variables
print("Name:", name, ", Age:",age) # display formatted output
By default, a single space ' ' acts as a separator between values. However,
any other character can be used by providing a sep parameter.
name=input("Enter your name: ")
print(type(name))
age=input("Enter your age: ")
print(type(age))
things
lowercase.
Get it by
help("keywords") 35 keywords
Here is a list of the Python keywords. Enter any keyword to get more help.
False class from or
None continue global pass
True def if raise
and del import return
as elif in try
assert else is while
async except lambda with
await finally nonlocal yield
print() is also used to display the value of variable
>>> print(n) #display value
>>> print(n + 2) # add and display the result
Variables in Python are objects. Use the type() function to get
the class name of an object.
>>> type(n)
The type of n is int. An object of int class contains a integer
literal 20
Depending upon the value they are all class
>>> msg='Hello World'
>>> type(msg)
>>> isPythonInterpreted = True
>>> type(isPythonInterpreted)
Python is a dynamically-typed language, which means you
don't need to declare a type of a variable. The type will be
assigned dynamically based on the assigned value.