Python — Variables

Alvif Sandana Mahardika
1 min readMar 29, 2021

--

Every programming language has a different way to declare its variable. Before we go, what are variables? Variables are used to store information to be referenced or manipulated in a computer program. Variables have various data types like integer, float, double, string, and many more. In the previous post, we have installed Python and PyCharm as our code editor. So, in this post, we will discuss variables in Python.

Rules when declaring variables

  • Case sensitive
  • Avoid using numbers to declaring variables. Example: not 3age but age3
  • Not need semicolon (;) at the end of the statement.
  • The existed variable can be re-assigned with a new value.

Creating Variable

Python has no specified command to define a new variable. Example:

You can re-assign existed variable with a new value. Example:

You can declare your variable to a specific data type with casting.

If you want to get your variable type, use type() function. Example:

Data Types

Python provides some data types:

  • Integer
  • Float
  • Complex Number
  • String
  • Boolean

to better understand, look at the following example.

Next post:

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Alvif Sandana Mahardika
Alvif Sandana Mahardika

Written by Alvif Sandana Mahardika

Write code with love. Code Your Life :)

No responses yet

Write a response