×

To install this app on your iPhone, tap Share 🔗 then Add to Home Screen.

06 Introduction to Python Variables

0
62

Basically, Python has no command to Declare a Variable. A Variable is created as soon as you assign any value to it. Whether it is numeric, String, Float, Boolean or any kind.

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

*** Variable names in Python are case-sensitive.

A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume)

Following are some rules to create a variable name:

  • A variable name must start with a letter or the underscore character
  • A variable name cannot start with a number
  • A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ )
  • Variable names are case-sensitive (age, Age and AGE are three different variables)

Example 01:

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

Example 02:

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

Example 03:

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

type() function:

You can get variable type using type() function.

Example:

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

Pesquisar
Categorias
Leia Mais
Food
How to Choose the Best Buffalo Desi Ghee Price 1kg in Market
Finding the right buffalo desi ghee price 1kg in today’s market can feel like a challenge....
Por DCc Ghee 2025-05-19 17:19:28 0
Outro
Menstrual Cup Market Research Report: Growth, Share, Value, Trends, and Insights
The worldwide "Menstrual Cup Market" 2025 Research Report presents a professional and complete...
Por Tushar Jane 2025-05-27 05:12:14 0
SEO
Buy BBB Reviews
Buy Trustpilot ReviewsWe provide 100% secure and fully verified Trustpilot review sat affordable...
Por Taylor Collins 2025-05-26 06:55:32 0
Crafts
Beyond Wires: How Socket Boxes Anchor Off-Grid Energy Independence
As climate-conscious homeowners abandon centralized grids for solar-microgrid independence, one...
Por Lars xinnyi 2025-05-21 09:30:02 0