...

Web Technologies - PYTHON

Back to Course

Lesson Description


Lession - #283 Python Scope



Scope of Python

A variable can only be accessed from within the region in which it was created. This is referred to as scope.

Local Scope A variable generated inside a function is part of the function's local scope, and it can only be utilised within that function.

Example
A variable defined within a function is accessible only within that function:

def myfun(>
: z = 400 print(z>
myfun(>

Output:

Sorry cannot be displayed Try it here

Global Scope

A global variable is one that is created in the main body of Python code and belongs to the global scope.

Global variables can be accessed from any scope, both global and local.

Example
A global variable is one that is created outside of a function and can be utilised by anyone:

a = 200

def myfunction(>
: print(a>
myfunction(>
print(a>

Output:

Sorry cannot be displayed Try it here

python requests

Requests is an exquisite and straightforward HTTP library for Python, worked for individuals.

What is map in Python? Map in Python is a capacity that fills in as an iterator to return an outcome in the wake of applying a capacity to each thing of an iterable (tuple, records, and so on.>
. It is utilized when you need to apply a solitary change capacity to every one of the iterable components. The iterable and work are passed as contentions to the guide in Python.

python questions for interview,python interview questions

Interview Questions

Python datetime

Import the datetime module and show this date: import datetime. x = datetime.datetime.now(>
...

Return the year and name of work day: import datetime. x = datetime.datetime.now(>
...

Make a date object: import datetime. ...

Show the name of the month: import datetime. ...

<