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))

Search
Categories
Read More
Other
産業用レーザービームプロファイラ市場戦略レポート2025:競合状況、成長要因、投資リスク
2025年7月16日に、QYResearch株式会社(所在地:東京都中央区)は、「産業用レーザービームプロファイラ―グローバル市場シェアとランキング、全体の売上と需要予測、2025~2031」の...
By Xu Shuyun 2025-07-16 05:36:04 0
Other
Naturally Beautiful: Growth Trends in the Organic Hair Care Market
"Executive Summary Organic Hair Care Market : CAGR Value Data Bridge Market Research...
By Dbmrraaj Sinha 2025-07-08 07:22:30 0
Books and Authors
Doctor Blade Market Poised for Robust Growth Amid Rising Demand from Printing and Packaging Industries
"Executive Summary Doctor Blade Market :  Data Bridge Market Research analyses...
By Komal Galande 2025-06-24 07:05:39 0
Other
世界光記録媒体産業調査:市場シェア、需要分析、投資報告2025
2025年6月17日に、YH Research株式会社(本社:東京都中央区)は、調査レポート「グローバル光記録媒体のトップ会社の市場シェアおよびランキング...
By Krystal Lin 2025-06-17 06:51:04 0
Omaada - A global social and professionals networking platform https://www.omaada.com