Blocks in Python are used to group statements for a specific purpose. Variables inside blocks have a limited scope and are only available within that block. Local variables defined inside a function are only accessible within the function, while global variables defined outside a function can be accessed anywhere in the program. Comments are used to explain code and come in single-line or multiline formats. Python supports basic datatypes like integers, floats, Booleans, strings, and arrays. It also has basic operators for arithmetic, comparison, assignment, and logical operations. Functions allow code reuse and are defined using the def keyword.
2. Blocks in Python
● Grouping of sentences for a specific purpose
● Piece of python program that is executed as a unit
● Can be called once or more
● Can invoke other code blocks
● Indentation used to denote block
● All statements with same indentation level - form one block
● If blocks have to be nested, indent further
3. Scope of Variables
● Defines visibility of a name within a block
● A variable is only available from inside the region it is created. This is called
scope.
● Same variable name inside and outside of a function, Python will treat them as
two separate variables.
4. Local vs Global variables
● Scope of global variables - for the entire
program
● Scope of local variables - only in the
function it is defined
● global keyword is used to
assign/change variables inside
functions
5.
6. Comments
● Comments for increasing understandability of code - for
yourself & others
● Types of Comments in Python
○ Single-Line
○ Multi-Line
10. Python Datatypes - int & float
● int (signed integers) − They are often called just integers
or ints, are positive or negative whole numbers with no
decimal point.
● float (floating point real values) − Also called floats, they
represent real numbers and are written with a decimal
point dividing the integer and fractional parts.
● Can use type() to get the datatype of a variable/value
11. Python Datatypes - Boolean
● Represented by 2 values: True and False
● These values are case-sensitive
23. What are keywords?
● Reserved words in Python
● Cannot use a keyword as a variable name, function name
● Keywords are case-sensitive
● If you try to use them as variables, you will end up with SyntaxError
● This can be used to get the keyword help("keywords")
25. global keyword
● Used if you want to make a change to the global variable inside a function.
● If you want to create a global variable from inside a function.