Expressions can be evaluated to a value like a+5 or a/b+c. Statements perform tasks and may or may not return a value, and can contain expressions. Comments are lines for documentation ignored by the compiler, starting with # in Python or enclosed in triple quotes. Functions perform independent subtasks and are reusable, assigned a unique name. Blocks contain groups of statements with the same indentation level. Python style rules include maximum line length of 70 characters, using indentation for blocks, and whitespace around operators.
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
17 views
Python 4
Expressions can be evaluated to a value like a+5 or a/b+c. Statements perform tasks and may or may not return a value, and can contain expressions. Comments are lines for documentation ignored by the compiler, starting with # in Python or enclosed in triple quotes. Functions perform independent subtasks and are reusable, assigned a unique name. Blocks contain groups of statements with the same indentation level. Python style rules include maximum line length of 70 characters, using indentation for blocks, and whitespace around operators.
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7
Expressions :
It is any legal combination of tokens which can be
evaluated to a value.
a+5 a / b +c a>b Statement : It is a programming instruction aimed to perform some specific task.
When an expression is evaluated, a statement is executed.
It may or may not be resulted in a value. A statement may contain an expression. Comments:
These are the remark lines written in a program for
documentation purpose. These are aimed for the programmers and ignored by the compiler. • Any line starting with # is a comment line in Python • A group of lines enclosed within triple quotes are comment lines (docstrings)
# This is a comment line
‘’’ These following lines
are comment lines also ‘’’ Functions : A function is a subprogram aimed to perform a single independent subtask and to be reused when needed. Every function is assigned a unique name and can be invoked by writing the name anywhere in the program. Blocks & Indentation : A group of statements when written as a part of another statement is known as a block or code-block or suite. if a>b : a=a+5 b=b-2 print(“Process done”) Statements in the same block should be within the same indentation. Python Style Rules and Conventions :
• There is no need of any statement termination
symbol • Maximum length of a line should be 70 characters • Blocks of codes are denoted by line indentations • Blank lines are used in between class / function definitions • Multiple statements in a line should be avoided though it is permitted by using ; as the separator • Whitespace characters should be used around the operators and after the punctuators. • Python is case sensitive and this must be kept in mind Variables : Variable is a named memory location that refers to a value which may change from time to time during program execution. Creating Variable : Python variables are created by assigning a value of desired type to them. Roll = 15 Name = ‘Abcdef’ Agg = 93.3 Python create labels referring to the values when variables are defined. Variables in other languages vs Variables in Python
• Unlike other languages variables in Python are not
storage containers • Unlike other languages variables in Python do not have fixed locations
Multiple Assignments
• Assigning same value to multiple variables
a = b = c = 10 • Assigning multiple values to multiple variables a, b, c = 10, 20, 30