Member-only story

Python Essentials: Understanding Variables and Datatypes

Pytech Academy
3 min readJul 30, 2023

In Python, variables are used to store and manipulate data. They act as placeholders for values that can be accessed and modified throughout the program. Python is a dynamically typed language, which means that variables can hold values of different data types.

Definition:

A variable in Python is created with a name and assigned a value using the assignment operator (=). The name of the variable should follow certain rules that are as follows:

#Creating a variable 'name'
name = "John"
print(name)

Rules for variables:

  1. Variable names must start with a letter or the underscore character (_). For example, _count, name, age.
  2. Variable names cannot start with a number. They should begin with a letter or underscore. For example, 1number is not a valid variable name.
  3. Variable names can only contain alphanumeric characters (letters and numbers) and underscores. Special characters and spaces are not allowed. For example, my_var, count_1, name2.
  4. Variable names are case-sensitive, which means that my_var and My_Var are considered as two different variables.
  5. Variable names cannot be a keyword, as keywords are reserved words in Python that have special meanings. For example, if, for, while are keywords and cannot be used as variable names.

Other notes: Python also allows you to assign values to…

--

--

Pytech Academy
Pytech Academy

Written by Pytech Academy

Python, web apps with Streamlit/Flask, AI/ML - Learn it all at Pytech Academy! Master coding and build projects in Python. #PytechAcademy

No responses yet