Python - Variables

A Python variable is a reserved memory location to store values. In other words, a variable in a python program gives data to the computer for processing. Every value in Python has a datatype.

Python is object oriented programming language. Every variable in Python is an object. There are Different types of variables.

  • Creating Variables

  • Multiple Variables

  • Output Variables

  • Global Variables

Creating Variables

To Create a Variable in Python,all you need to specify the variable name then assign a value to it

<variable name> = <value>

Python uses = to assign value to variables.There's no need to declare in advance,assigning a value to a variable itself declares and initializes the variable with that value.There is no way to declare a variable without assigning it an intial value.


a = 2
b = "sri" 

#output = 2
#output = sri

Multiple Variables

Python allows you to assign values to multiple variables in one line

< variable names> = < value1,value2,value3.....>


a, b, c = 1, 2, 3
print(a, b, c)

#output: 1 2 3

Output Variables

The Python 'print' statement is often used to output variables.

To combine both text and a variable, Python uses the + character

a = "language"
print("Python is a " + a)

#output: Python is a language

For numbers, the + character works as a mathematical operator

a = 4
b = 3
print(a + b)

#output: 7

Global Variable

Variables that are created outside of a function (as in all of the examples above) are known as global variables.
Global variables can be used by everyone, both inside of functions and outside.

a = "language"

def myfunc():
  print("Python is a " + x)


#output: Python is a language


Python - RegEx SETS

posted on 2019-11-12 23:06:24 - Python Tutorials


Python - RegEx_Functions

posted on 2019-11-09 06:07:29 - Python Tutorials


Python - RegEx_Sets

posted on 2019-11-09 05:30:54 - Python Tutorials

Prompt Examples

ChatGPT Prompt Examples

posted on 2023-06-21 22:37:19 - ChatGPT Tutorials

Use Cases

Chat GPT Key Use Cases

posted on 2023-06-21 21:03:17 - ChatGPT Tutorials

Prompt Frameworks

Prompt Frameworks

posted on 2023-06-21 19:33:06 - ChatGPT Tutorials