Learn Dedaandsons

Story: Python for beginners: Variables and their Data Types; 31.08.23;

Variables and Data Types (commonly used) in Python.

A variable in Python is a named location in memory that stores a value.

The variable name must start with a letter or an underscore, which can contain letters, numbers, and underscores. Variable names are case-sensitive, so name and NAME are two different variables.

Here are commonly used Data Types in Python:

Integer : any number without a decimal point.

smr =int (5 +10) print (smr)

Float : it stores values in decimal like 25.0, 1.5 etc.

smr = float(20.5)

String: A string is a sequence of characters. Examples of strings are “Hello world!”, “This is a string”, “12345”, etc.

smr = str("Hello World")

Boolean : A boolean is a value that can be either True or False.

smr = bool(5)

Lists: A sequence of values, enclosed in square brackets. The values in a list can be of any data type. Ex. are List[1, 2, 3], ['a', 'b', 'c'], [True, False, None].

smr = list(("apple", "banana", "cherry"))

Tuples: A sequence of values, enclosed in parentheses. The values in a tuple cannot be changed. Examples are (1, 2, 3), ('a', 'b', 'c'), (True, False, None).

smr = tuple(("apple", "banana", "cherry"))

Dictionaries: A collection of key-value pairs, enclosed in curly braces. The keys must be unique, but the values can be of any data type. Examples are {'name': 'John Doe', 'age': 30}, {'fruits': ['apple', 'banana', 'orange']}.

smr = dictionaries{'name': 'John Doe', 'age': 30}


This tutorial may have been created with the assistance of artificial intelligence (AI) tools. Some of the research data used to write this tutorial may have been derived by AI tools, and then put together by humans. Additionally, AI tools may have been used to write some or all of the tutorial.


Move Back to Top

Like, share, follow us.