Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

2. Python_Variables

The document provides an introduction to Python programming, emphasizing the importance of case sensitivity in keywords and variable names. It outlines rules for naming variables, including the use of underscores, restrictions on starting with numbers, and avoiding keywords. Additionally, it demonstrates variable assignment and the ability to overwrite variable values.

Uploaded by

prpt2608
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

2. Python_Variables

The document provides an introduction to Python programming, emphasizing the importance of case sensitivity in keywords and variable names. It outlines rules for naming variables, including the use of underscores, restrictions on starting with numbers, and avoiding keywords. Additionally, it demonstrates variable assignment and the ability to overwrite variable values.

Uploaded by

prpt2608
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

In [1]: print("welcome to the world of coding")

welcome to the world of coding

In [3]: Print("welcome to the world of coding") ##### P is capital so wont't work, Keywork should always start with small letter

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[3], line 1
----> 1 Print("welcome to the world of coding")

NameError: name 'Print' is not defined

In [ ]: #### Notes
#1. Python is case sensitive
#2. Set of predefined keywords

#Variables

#1. Variables are placeholders, store it and it will be useful for future
#2. Variables are case-sensitive
#3. As the name suggests variables can vary (we can overwrite)
#4. Only one special Character is allowed i.e _(underscore), space and other special characters are not allowed
#5. The variable name should be a single-word
#6. It can end with a number but cannot start with a number
#7. Don't use keywords as variable name
#8. We can assign value to a variable by using =
#9. Variables Can be Overwritten or changed

In [1]: a = 5
print(a)

In [2]: print(A) ### This shows that python is case sensitive

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[2], line 1
----> 1 print(A)

NameError: name 'A' is not defined

In [6]: a= 3
b= 5
c=(a+b)

In [7]: print(c)

In [9]: a=4
b=2
c=a+b

In [10]: print(c)

In [ ]: #Naming of variables
totalstudents = 75 #### acceptable
total_student = 75 # acceptable
ts = 75 #### acceptable
TotalStudents = 75 #### acceptable
total@students = 75 #### not acceptable coz. no other special character other than _
_total_students = 75 #### acceptable
total_students7 = 75 #### acceptable coz. variable can end with number
7total_students = 75 #### not acceptable coz it starts with number

In [1]: total_students=75
type(total_students)

Out[1]: int

In [1]: dhoni_player="captain"
type(dhoni_player)

Out[1]: str

In [4]: Dhoni="The best finisher"

In [5]: print(Dhoni)

The best finisher

In [6]: Dhoni7 = "Best Cricketer"

In [7]: print(Dhoni7)

Best Cricketer

In [3]: institute="KSR Datavizon"


print(institute)

KSR Datavizon

In [4]: type(institute)

Out[4]: str

In [5]: a="sunil"
b='sunil'

print(a)

sunil

In [6]: print(b)

sunil

In [7]: type(a)

Out[7]: str

In [8]: type(b)

Out[8]: str

In [8]: KSR = "The Best Institute"

In [9]: print(KSR)

The Best Institute

In [10]: a = 70

In [11]: print(a)

70
In [12]: a = 80

In [13]: print(a) #### Variables can be overwritten

80

You might also like