0% found this document useful (0 votes)
2 views6 pages

Python Variables

The document provides an overview of Python variables, explaining that they are created when a value is assigned without a specific declaration. It discusses variable types, casting, and the case sensitivity of variable names. Examples illustrate how to create variables, change their types, and check their data types using the type() function.

Uploaded by

Fack BooK
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Python Variables

The document provides an overview of Python variables, explaining that they are created when a value is assigned without a specific declaration. It discusses variable types, casting, and the case sensitivity of variable names. Examples illustrate how to create variables, change their types, and check their data types using the type() function.

Uploaded by

Fack BooK
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

03/08/2026, 08:20 Python Variables

 Tutorials  References  Exercises  Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP [Link] C C++

Python Variables
❮ Previous Next ❯

Variables
Variables are containers for storing data values.

Creating Variables
Python has no command for declaring a variable.

A variable is created the moment you first assign a value to it.

Example Get your own Python Server

x = 5
y = "John"
print(x)
print(y)

Try it Yourself »

Variables do not need to be declared with any particular type, and can even change type
after they have been set.

Example

x = 4 # x is of type int
x = "Sally" # x is now of type str

[Link] 1/6
03/08/2026, 08:20 Python Variables

print(x)
 Tutorials  References  Exercises  Sign In

 Try itCSS
HTML YourselfJAVASCRIPT
» SQL PYTHON JAVA PHP [Link] C C++

Casting
If you want to specify the data type of a variable, this can be done with casting.

Example

x = str(3) # x will be '3'


y = int(3) # y will be 3
z = float(3) # z will be 3.0

Try it Yourself »

Get the Type


You can get the data type of a variable with the type() function.

Example

x = 5
y = "John"
print(type(x))
print(type(y))

Try it Yourself »

You will learn more about data types and casting later in this tutorial.

[Link] 2/6
03/08/2026, 08:20 Python Variables

Single
 or Double
Tutorials References Quotes?
Exercises  Sign In

HTML CSS
String variables JAVASCRIPT either byPYTHON
can be declared SQL using singleJAVA PHP
or double quotes:[Link] C C++

Example

x = "John"
# is the same as
x = 'John'

Try it Yourself »

Case-Sensitive
Variable names are case-sensitive.

Example
This will create two variables:

a = 4
A = "Sally"
#A will not overwrite a

Try it Yourself »

?
Exercise
What is a correct way to declare a Python variable?

var x = 5

#x = 5
[Link] 3/6
03/08/2026, 08:20 Python Variables

 $x = 5
Tutorials References  Exercises  Sign In

HTML
 x = 5JAVASCRIPT
CSS SQL PYTHON JAVA PHP [Link] C C++

Submit Answer »

Video: Python Variables

❮ Previous Sign in to track progress Next ❯

[Link] 4/6
03/08/2026, 08:20 Python Variables

 Tutorials  References  Exercises  Sign In

HTML
 CSS JAVASCRIPT SQL PYTHON JAVA PHP [Link] C C++

 

-->
 PLUS SPACES

GET CERTIFIED FOR TEACHERS

BOOTCAMPS CONTACT US

Top Tutorials
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
How To Tutorial
SQL Tutorial
Python Tutorial
[Link] Tutorial
Bootstrap Tutorial
PHP Tutorial
Java Tutorial
C++ Tutorial
jQuery Tutorial

Top References
HTML Reference
CSS Reference
[Link] 5/6
03/08/2026, 08:20 Python Variables
JavaScript Reference

 Tutorials  SQL Reference


References 
Python Reference
Exercises  Sign In
[Link] Reference
HTML
 CSS JAVASCRIPTReference
Bootstrap SQL PYTHON JAVA PHP [Link] C C++
PHP Reference
HTML Colors
Java Reference
AngularJS Reference
jQuery Reference

Top Examples Get Certified


HTML Examples HTML Certificate
CSS Examples CSS Certificate
JavaScript Examples JavaScript Certificate
How To Examples Front End Certificate
SQL Examples SQL Certificate
Python Examples Python Certificate
[Link] Examples PHP Certificate
Bootstrap Examples jQuery Certificate
PHP Examples Java Certificate
Java Examples C++ Certificate
XML Examples C# Certificate
jQuery Examples XML Certificate

    

FORUM ABOUT ACADEMY


W3Schools is optimized for learning and training. Examples might be simplified to improve reading and
learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full
correctness
of all content. While using W3Schools, you agree to have read and accepted our terms of use, cookies
and privacy policy.

Copyright 1999-2026 by Refsnes Data. All Rights Reserved. W3Schools is Powered by [Link].

[Link] 6/6

You might also like