Learning Python: Variables in Python

Introduction to blog series

This blog post will be part of a series of blog posts which I will be publishing regarding what I have been reviewing and learning in Python.

Variables in Python

Variables in Python can be declared either with a data type or without one. For example, if we want to declare a variable of type string, we would do the following:

message = str("Hello World")

We can also declare it without any declaration or type hinting of the data type and leave it up to the interpreter to figure it out as follows:

message = "Hello World"

Checking data type of variable

In the latter case if we want to find out the data type, we would do the following:

NOTE: # is used to comment in Python

type(message) #<class, 'str'>


isinstance(message, str) #True

This blog post was originally published on my blog Communicode, where I write about different tech topics.

Avatar for Muhammad Asfour

Written by Muhammad Asfour

I am a Full Stack Developer with over 5 years of experience. I have worked with different tech stacks such as: Groovy/Java, PHP, .NET/.NET Core (C#), Node.js, React, Angular, and Vue.


Fetching comments

Hey! 👋

Got something to say?

or to leave a comment.