How to create variables in Python?

Python variable creation is very easy! You don’t have to define the datatype of a variable before creating it! All you need to do is think of a meaningful name and assign a value to it. The value assigned to the variable determines its datatype.

Rules for user variable names in Python

  1. User variables must begin with Alphabet
  2. Underscores and numbers can be used only after the first alphabet

Camel Casing: The preferred way to create variables

CamelCasing is the style of creating variable names which are easy to read. so instead of naming your variables like x, y, z, foo, bar! Use better names which can help you understand your own code after six months!

For example if you are storing dates in some variables, then, names like “DateOfBirth” or “Date_of_Birth” are easily understood as compared to “d1” or “d2”


Sample valid python variables


Sample Invalid python variables


Python variable datatypes

There are many variable types in Python 3. Here is a list of the most common types:

  • bool (Boolean)
  • int (Integer/Long)
  • float (decimal values)
  • complex
  • string

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!

Leave a Reply!

Your email address will not be published. Required fields are marked *