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
Health
Comparing the Best Dentists for Root Canal in Islamabad
Root canal therapy is a delicate dental procedure that requires precision, experience, and...
Por Iqra Iftikhar 2025-07-17 07:54:19 0
Outro
Decanediol Market Anticipating Predictable Sustainable Evolution: Insights by Fact MR
The Global decanediol market is estimated to be valued at US$ 71.6 million in 2023 and...
Por Akshay Gorde 2025-06-12 13:24:35 0
Health
Vitamins and Minerals Market Valued at USD 61.8 Billion in 2025
The global vitamins and minerals market continues to thrive in 2024, driven by heightened...
Por Ganesh Raut 2025-07-21 03:52:02 0
Outro
耐摩耗性PPS市場調査レポート:主要企業、競合分析、成長動向2025-2031
2025年6月18日に、QYResearch株式会社(所在地:東京都中央区)は、「耐摩耗性PPS―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の調査資料を発行しま...
Por Xu Shuyun 2025-06-18 03:49:46 0
Crafts
Asia-Pacific Amino Acid Based Biostimulants Market Thrives with Push for Sustainable Agriculture
"Executive Summary Asia-Pacific Amino Acid Based Biostimulants Market : Data Bridge...
Por Komal Galande 2025-07-04 06:44:04 0
Omaada - A global social and professionals networking platform https://www.omaada.com