#36 Python Tutorial for Beginners | Global Keyword in Python | Global vs Local Variable

preview_player
Показать описание
Check out our courses:

Coupon: TELUSKO10 (10% Discount)

For More Queries WhatsApp or Call on : +919008963671

In this lectre we are discussing:
#1 Scope of variable
#2 Local variable
#3 Global variable
#4 Global keyword
#5 Global() function

#1 Scope of variable
-- scope of variable means where we can access the variable
-- there are two types of scope of variable
1. local scope
2. global scope

#2 Local variable
-- local variable means variable which is defined inside the function
-- we can access the local variable inside the function only
-- we cannot access the local variable outside the function

Local Scope:
When a variable or function is defined inside a function, it is said to be in the local scope of that function.
Variables defined in the local scope are only accessible within that function and are destroyed once the function
completes execution. Local variables have the highest priority in accessing over global variables of the same name.

def func():
x = 10
print(x)
func()
-- the variable x is defined inside the function, and it can only be accessed within the function.

#3 Global variable
-- global variable means variable which is defined outside the function
-- we can access the global variable inside the function
-- we can access the global variable outside the function

x = 10
def func():
print(x)
func()

-- the variable x is defined outside the function, and it can be accessed within the function.

#4 Global keyword
-- if we want to access the global variable inside the function and we want to change the value of
global variable inside the function then we have to use global keyword.

x = 10
def func():
global x
x = 15
print(x)
func()

-- in this case no new variable is created inside the function,
but the global variable x is accessed and modified inside the function.

#5 Global() function
-- if we want to access the global variable inside the function and we want to change the value of global variable
inside the function then we have to use global() function.

e.g
x = 10
def func():
x = 15
print("local x: ",x)
y = globals()['x']
print("global x: ",y)
globals()['x'] = 20

-- using globals()['x'] we can access the global variable x inside the
function and we can change the value of global variable x inside the function.

Python Tutorial to learn Python programming with examples

Subscribe to our other channel:
Telusko Hindi :
Рекомендации по теме
Комментарии
Автор

No trash talk, straight to topic, optimal speed and able to explain the concept within 10 minutes . This guy is a gem 💎. Respect 🙏

aravindor
Автор

Great sense of humour and teaching skills! Keep going !

harshnandu
Автор

I will definitely recommend your tutorials to a python beginner sir.

karthik
Автор

This 10 min video 2-3 hours of college lecture

Thank you so much sir ❤

vaibhavsoni
Автор

Plzz give him a like bezz no one will teach like this if we pay also 🙏🙏

God bless you and your family sir :)

harshabasavaraju
Автор

I really appreciate your efforts and your determination!! You and newboston were the reasons i got comfortable in programming!!👌🏻

dance
Автор

Still one of the best tutors even in 2024. Thank you Navin !

christianihechi
Автор

These 8 minutes tought me 40 minutes of lecture.. Hats Off To You Sir!

PassionateSaksham
Автор

Sir you are an outstanding teacher
Hard to find people like you who provide help to the students, that too free of cost
Very appreciable
Thanks once again

_jaishreerana
Автор

Great job sir !
you r providing us such
precious video lectures for free .
I'm heartily thankful to u. 🤗

nirmalkatiyar
Автор

One of the best explanations possible to anything, thank you man!

guillermoriveranunez
Автор

Why youtube was not there during my college days. Life would have been so easy.
And I must say, you are a very good teacher. I wish you get some cards on Sep 5th every year.

anuragray
Автор

Offo man. You are nice guy and concept are cleared in 10 min. god bless you man. I am big fan of your way of teaching.

kodidatascientist
Автор

Sir your tuturioals are the best their very precise to the point, so not even a second of your lecture is not important and also its very helpful how make these videos and teach us in a very simple manner

sanjeevKumar-eghp
Автор

Awesome man, I was stuck for 1 hour on that, tyvm

Nalanarud
Автор

Great sir 🙏🙏.. Your videos are always concise, deep knowledgeable and elaborative.. now with nice animation graphics.. Just the best sir 👍👍🤗..

chinmaydas
Автор

Apki jitni tarif ki jaye kam h but main apse yhi rqust krunga k ap aise hm jaise.kmzor students k liye video banate rhe its rlly helpful.for us kisi r ka toh pta nhi pr mere liye bht bht zyada beneficial tha ye so thnk u vry much

shamstabrez
Автор

Im am practicing deligently sir for not making any mistakes tq sir for giving us free 🤝🤝

b.sasikumar
Автор

Heard this from multiple people, understood for the first time, thanks a lot

sanijawijesinghe
Автор

We really appreciate you sir you do hardwork for us thankyou sir salute to you👏👏

pavanjain