Lecture-03 Python Variables
Lecture-02 Python Variables
- A Python variable name must start with a letter or the underscore character.
- A Python variable name cannot start with a number.
- A Python variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ).
- Variable in Python names are case-sensitive (name, Name, and NAME are three different variables).
- The reserved words(keywords) in Python cannot be used to name the variable in Python.
PythonVariable
To Assign the value to a variable
"="--> this symbol called as "Assignment"
x=20
Variable name = Value of variable
print(x)
o/p =20
Memory location of address
address of x
--------------------
x=20
print(x)
id(x)
o/p = 20
address of x
--------------------
y = "Hello World"
print(y)
print(y)
id(y)
o/p = Hello World
Rules of Variable
variable is case-sensitive
Rules of Variable
a = 2
b = 5
c = a + b
print (c)
o/p:7
_var = 89
var = 100
var38238gu=67.9
a-zA-Z = 200
Avar = 250
AvaR = 300
Var = 350
VAR = 400
myVar =
my_var =
3var = 450-----_> invalid (cannot assign to operator)
var_2 = 500
var - 2 = 550 --> invalid (cannot assign to operator)
"-" this like minus symble
Avar = 20
Avar - 5
o/p = 20 - 5 = 15
my var = 600. ---> invalid
var 4 = 610 ---> invalid (its not allowed inavlid syntax error)
var_4 = 620
print(var_4)
o/p =620
sagar=10
print(sagar)
o/p:10
_sagar = 11
print(_sagar)
o/p: 11
11 sagar=12
print(11 sagar)
o/p:
Cell In[17], line 1
11 sagar=12 ^ SyntaxError: invalid syntax
11sagar = 13
print(11sagar)
o/p:
Cell In[19], line 1 11sagar = 13 ^ SyntaxError: invalid decimal literal
Sagar =14
print(Sagar)
o/p:14
SAGAR = 15
print(SAGAR)
O/P: 15
16 = "SAGAR"
print(16)
o/p:
Cell In[27], line 1
16 = "SAGAR" ^ SyntaxError: cannot assign to literal here. Maybe you meant '==' instead of '='?
-------------------------------------------------------------------------------------------------
Variables in Python
Variables need not be declared first in python. They can be used directly. Variables in python are case-sensitive as most of the other programming languages.
Variables need not be declared first in python. They can be used directly. Variables in python are case-sensitive as most of the other programming languages.
Python లో వేరియబుల్స్
- Python లో వేరియబుల్స్ ముందుగా డిక్లేర్ చేయవలసిన అవసరం లేదు. వీటిని నేరుగా ఉపయోగించవచ్చు.
- Python లో వేరియబుల్స్ కేస్ సెన్సిటివ్ (case-sensitive) ఉంటాయి, మిగతా చాలా ప్రోగ్రామింగ్ భాషల లాగా.
- name = "Python" # డిక్లేర్ చేయనవసరం లేదు
- Name = "Programming" # Name అనే వేరియబుల్ name కంటే వేరు
name,NameమరియుNAMEమూడు వేర్వేరు వేరియబుల్స్.
MORE EXAMPLES
total_price = 1
my_variable_name = 2
i = 3
i
PI = 4
MAX_SIZE = 5
__init__
#starting of variable double underscore is invalid o/p showing
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[17], line 1 ----> 1 __init__ NameError: name '__init__' is not defined
---------------------------------------------------------------------------sagar__ = 6
__SAGAR = 7
__Sagar = 8
__sagar__ = 9
__init__ = 10
__str__ = 11
# Avoid naming your variables with names that match Python built-ins like.
Python బిల్ట్-ఇన్ పేర్లను వేరియబుల్స్ కోసం ఉపయోగించకండి
list,str,dict,intవంటి బిల్ట్-ఇన్ పేర్లను వేరియబుల్స్ కోసం ఉపయోగించడం మంచిది కాదు.- ఇలా చేస్తే Python లో బిల్ట్-ఇన్ ఫంక్షన్లు మరియు ఆబ్జెక్టులని ఓవర్రైట్ (overwrite) చేస్తారు, ఇది సమస్యలకు దారి తీస్తుంది.
- తప్పు ఉదాహరణ:
- list = [1, 2, 3] # ఇది బిల్ట్-ఇన్ `list()` ఫంక్షన్ను పాడుచేస్తుంది
- సరైన ఉదాహరణ:
- my_list = [1, 2, 3] # సరికొత్త పేరు ఉపయోగించడం ద్వారా సమస్యను నివారించవచ్చు
- గమనిక: ఎల్లప్పుడూ మీ వేరియబుల్స్ కోసం అర్థవంతమైన మరియు బిల్ట్-ఇన్ పేర్లకు దూరంగా ఉండే పేర్లను ఎంపిక చేసుకోండి.
list = 12
str = 13
disct = 14
#Rules of Variables
sagar = 15
Sagar = 16
SagaR = 17
SAGAR = 18
sAgAr = 19
vidya sagar = 20 #space between the variable is invalid 0/p
Cell In[43], line 1 vidya sagar = 20 ^ SyntaxError: invalid syntax
---------------------------------------------------------------------------vidyasagar = 21
vidya_sagar = 22
#minus is a assignmet operatos so it is not valid it is invalid for inbetween the variable.# మైనస్ అనేది అసైన్మెంట్ ఆపరేటర్ కాదు, ఇది వేరియబుల్ మధ్యలో చెల్లదు. ఇది తప్పు.
వివరణ:
- Hyphen (-) ని వేరియబుల్ పేర్లలో ఉపయోగించలేరు, ఎందుకంటే Python లో ఇది మైనస్ ఆపరేటర్గా భావించబడుతుంది.
- వేరియబుల్స్ పేరు కోసం అండర్స్కోర్ (_) మాత్రమే చెల్లుతుంది.
తప్పు ఉదాహరణ:
my-variable = 10 # ఇది లోపం చూపిస్తుంది
సరైన ఉదాహరణ:my_variable = 10 # అండర్స్కోర్ ఉపయోగించడం ద్వారా ఇది సరైనది
గమనిక: వేరియబుల్ పేర్లు మాత్రమే అక్షరాలు, సంఖ్యలు, మరియు అండర్స్కోర్ను కలిగి ఉండాలి. 😊
Ex:
vidya-sagar = 23 Cell In[49], line 1 vidya-sagar = 23 ^ SyntaxError: cannot assign to expression here. Maybe you meant '==' instead of '='?-------------------------------------------------5vidyasagar = 24 #variable front number not valid showing errorCell In[51], line 1 5vidyasagar = 24 ^ SyntaxError: invalid decimal literal-------------------------------------------------vidyasagar5 = 25vidya6sagar = 26vidya_7_sagar = 27
-------------------------------------------------7 vidya_sagar = 28 #space not validCell In[59], line 1 7 vidya_sagar = 28 ^ SyntaxError: invalid syntax-------------------------------------------------vidyasagar 8 = 29Cell In[5], line 1 vidyasagar 8 = 29 ^ SyntaxError: invalid syntax-------------------------------------------------VidyasagaR 9 = 30Cell In[7], line 1 VidyasagaR 9 = 30 ^ SyntaxError: invalid syntax
-------------------------------------------------VIDYASAGAR 11 = 31Cell In[9], line 1 VIDYASAGAR 11 = 31 ^ SyntaxError: invalid syntax-------------------------------------------------
Comments
Post a Comment