DataType in Python

The type() function can be used to define the values of various data types and to check their data types.

Python3
# DataType Output: str
x = "Hello World"

# DataType Output: int
x = 50

# DataType Output: float
x = 60.5

# DataType Output: complex
x = 3j

# DataType Output: list
x = ["geeks", "for", "geeks"]

# DataType Output: tuple
x = ("geeks", "for", "geeks")

# DataType Output: range
x = range(10)

# DataType Output: dict
x = {"name": "Suraj", "age": 24}

# DataType Output: set
x = {"geeks", "for", "geeks"}

# DataType Output: frozenset
x = frozenset({"geeks", "for", "geeks"})

# DataType Output: bool
x = True

# DataType Output: bytes
x = b"Geeks"

# DataType Output: bytearray
x = bytearray(4)

# DataType Output: memoryview
x = memoryview(bytes(6))

# DataType Output: NoneType
x = None

List in Python

The Python list is a sequence data type that is used to store the collection of data. Tuples and String are other types of sequence data types.

Python3
Var = ["Geeks", "for", "Geeks"]
print(Var)

Output:

['Geeks', 'for', 'Geeks']

List comprehension

A Python list comprehension is made up of brackets carrying the expression, which is run for each element, as well as the for loop, which is used to iterate over the Python list’s elements.

Also, Read – Python Array

Python3
# Using list comprehension to iterate through loop
List = [character for character in [1, 2, 3]]

# Displaying list
print(List)

Output:

[1, 2, 3]

Dictionary in Python 

A dictionary in Python is a collection of key values, used to store data values like a map, which, unlike other data types holds only a single value as an element.

Python3
Dict = {1: 'Geeks', 2: 'For', 3: 'Geeks'}
print(Dict)

Output:

{1: 'Geeks', 2: 'For', 3: 'Geeks'}

Python Dictionary Comprehension

Like List Comprehension, Python allows dictionary comprehension. We can create dictionaries using simple expressions. A dictionary comprehension takes the form {key: value for (key, value) in iterable}

Python3
# Lists to represent keys and values
keys = ['a','b','c','d','e']
values = [1,2,3,4,5]

# but this line shows dict comprehension here
myDict = { k:v for (k,v) in zip(keys, values)}

# We can use below too
# myDict = dict(zip(keys, values))

print (myDict)

Output:

{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}

Tuples in Python

Tuple is a list-like collection of Python objects. A tuple stores a succession of values of any kind, which are indexed by integers.

Python3
var = ("Geeks", "for", "Geeks")
print(var)

Output:

('Geeks', 'for', 'Geeks')

Sets in Python

Python Set is an unordered collection of data types that can be iterated, mutated and contains no duplicate elements. The order of the elements in a set is unknown, yet it may contain several elements.

Python3
var = {"Geeks", "for", "Geeks"}
print(var)

Output:

{'for', 'Geeks'}

Python Cheat sheet (2024)

Python is one of the most widely-used and popular programming languages, was developed by Guido van Rossum and released first in 1991. Python is a free and open-source language with a very simple and clean syntax which makes it easy for developers to learn Python. It supports object-oriented programming and is most commonly used to perform general-purpose programming. Python is used in several domains like Data Science, Machine Learning, Deep Learning, Artificial Intelligence, Scientific Computing Scripting, Networking, Game Development Web Development, Web Scraping, and various other domains.

Python Cheat Sheet

To give a comprehensive overview of Python programming, we made a Python Cheat Sheet for Python programmers. In this Cheat Sheet of Python, you’ll learn all the basic to advanced topics and concepts of Python, like Python data types, Python for loop, Python slice, python map function, python dictionary, Python File Handling, etc.

Python Cheat sheet

  • What is Python?
  • Python Input
  • Operators in Python
  • Python Comment
  • DataType in Python
  • Python String
  • Conditional Statements
  • Python Functions
  • Python BuildIn Function
  • Python RegEx
  • File Handling in Python
  • Try and Except Statement
  • Python OOPs Concepts
  • Python Modules
  • Python Interview Questions Answers
  • Python Cheat Sheet – FAQs

Similar Reads

What is Python?

Python is one of the most widely-used and popular programming languages, was developed by Guido van Rossum and released first on February 20, 1991. Python is a free and open-source language with a very simple and clean syntax which makes it easy for developers to learn Python. It supports object-oriented programming and is most commonly used to perform general-purpose programming. Python is used in several domains like Data Science, Machine Learning, Deep Learning, Artificial Intelligence, Scientific Computing Scripting, Networking, Game Development Web Development, Web Scraping, and various other domains....

Python Input

The input() method in Python is used to accept user input. By default, it returns the user input as a string. By default, the input() function accepts user input as a string....

Operators in Python

In general, Operators are used to execute operations on values and variables. These are standard symbols used in logical and mathematical processes....

Python Comment

Comments in Python are the lines in the code that are ignored by the interpreter during the execution of the program. There are three types of comments in Python:...

DataType in Python

The type() function can be used to define the values of various data types and to check their data types....

Python String

In Python, a string is a data structure that represents a collection of characters. A string cannot be changed once it has been formed because it is an immutable data type....

Conditional Statements

Decision-making statements in programming languages decide the direction(Control Flow) of the flow of program execution....

Python Functions

Python Functions are a collection of statements that serve a specific purpose. The idea is to bring together some often or repeatedly performed actions and construct a function so that we can reuse the code included in it rather than writing the same code for different inputs over and over....

Python BuildIn Function

There are numerous built-in methods in Python that make creating code easier. Learn about the built-in functions of Python in this post as we examine their numerous uses and highlight a few of the most popular ones....

Python RegEx

We define a pattern using a regular expression to match email addresses. The pattern r”\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}\b” is a common pattern for matching email addresses. Using the re.search() function, the pattern is then found in the given text. If a match is found, we use the match object’s group() method to extract and print the matched email. Otherwise, a message indicating that no email was found is displayed....

File Handling in Python

Python too supports file handling and allows users to handle files i.e., to read and write files, along with many other file handling options, to operate on files....

Try and Except Statement

In Python, Try and except statements are used to catch and manage exceptions. Statements that can raise exceptions are kept inside the try clause and the statements that handle the exception are written inside except clause....

Python OOPs Concepts

Object-oriented Programming (OOPs) is a programming paradigm in Python that employs objects and classes. It seeks to include real-world entities such as inheritance, polymorphisms, encapsulation, and so on into programming. The primary idea behind OOPs is to join the data and the functions that act on it as a single unit so that no other portion of the code can access it....

Python Modules

A library is a group of modules that collectively address a certain set of requirements or applications. A module is a file (.py file) that includes functions, class defining statements, and variables linked to a certain activity. The term “standard library modules” refers to the pre-installed Python modules....

Python Interview Questions Answers

Python Interview Questions Answers...

Python Cheat Sheet – FAQs

Q. What are the key features of Python?...

Contact Us