Python variable names

Variables Names

The rules for naming a variable have been mentioned before. The multi-word variable can be named in the following three ways.

  • Camel Case - In the camel case, each word in the middle has its first alphabet in capitals. There is no whitespace in between.
    For example – nameOfSchool,valueOfBankaccount, etc.
  • Pascal Case - It is mostly the same as the Camel Case, but here the first word also needs to start with an uppercase letter.
    For example - NumberOfApplicants, etc.
  • Snake Case - In the snake case, words are separated with the underscore in between.
    For example - number_of_applicants, etc.

The variables are just like containers for storing data values.

Creating Variables in Python:

There is no command in Python for declaring a variable. The variable is formed at the time when you first specify a value to it.

Casting in Python:

If you want to define the data type of a variable in Python, it can be done with casting.

Some rules of Python are mentioned below with example:-

  • The name of the variable in Python must start with a letter or with an underscore character.
    {Like for example, Myname and _myname}.
  • The name of the variable must not begin with a number.
    { 1disc is a wrong way to write the name of a variable}.
  • The name of the variable can consist of alphanumeric characters and underscores only.
    (Such as from A-z, 0-9, and _ ).
  • The variable name in Python is case-sensitive.
    {Like for example, name, NAME, and Name are three different things}.
  • The variable can be a short name (like n and m) or a more detailed name
    (like index, surname, total_volume).

In several programming languages, variables are typed statically. But in the case of the python programming language, variables are not subject to this restriction. A variable may be allotted a value of one type, and later on, the value can be re-assigned with a different type.