×

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
Outro
Asia-Pacific UPS Battery Market Size, Trends & Forecast 2025
Asia Pacific UPS Battery Market: The Asia-Pacific region is a dynamic and rapidly growing market...
Por Reshama Patil 2025-06-09 08:50:19 0
Outro
Global Weight Loss App Market Poised for Robust Expansion Amidst Growing Health Awareness
The Weight Loss App Market is experiencing significant growth as digital health solutions gain...
Por Riya Sharma 2025-05-28 11:44:01 0
Outro
Material-Based Hydrogen Energy Storage Market Sees Growth in Renewables
Material-Based Hydrogen Energy Storage Market is growing due to clean energy demand, tech...
Por Lisa Tate 2025-05-27 09:42:30 0
Outro
How Rice Husk Suppliers Are Driving Sustainable Innovation in Agriculture and Industry
In the age of sustainability and eco-conscious business practices, agricultural by-products are...
Por Udyam Online 2025-06-03 05:09:43 0
Outro
ピストルグリップリバーシブルエアドリルの最新調査レポート:市場規模、競合環境、成長要因2025
2025年6月9日に、QYResearch株式会社(所在地:東京都中央区)は「ピストルグリップリバーシブルエアドリル―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」...
Por Qyresearch Jasmine1 2025-06-09 09:18:44 0