0% found this document useful (0 votes)
15 views2 pages

Python Variables and Data Types Guide

The document provides an overview of Python variables and data types, emphasizing that variables are dynamically typed and must follow specific naming rules. It outlines various built-in data types including numeric, text, sequence, mapping, set, boolean, and binary types, along with type conversion methods and the use of the type() function to check data types. Additionally, it highlights the concept of dynamic typing where variables can change types at runtime.

Uploaded by

drsanap0449
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Python Variables and Data Types Guide

The document provides an overview of Python variables and data types, emphasizing that variables are dynamically typed and must follow specific naming rules. It outlines various built-in data types including numeric, text, sequence, mapping, set, boolean, and binary types, along with type conversion methods and the use of the type() function to check data types. Additionally, it highlights the concept of dynamic typing where variables can change types at runtime.

Uploaded by

drsanap0449
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Variables and Data Types - Notes

1. Variables in Python
• Variables are containers used to store data values.
• You don’t need to declare the type; Python determines it automatically (dynamic typing).

Rules for Naming Variables:


• Must start with a letter or underscore (_).
• Cannot start with a number.
• Can contain letters, digits, and underscores.
• Case sensitive (age, Age, AGE are different).

Examples:
x = 10
name = "Sumedh"
_price = 99.5

2. Data Types in Python


Python has several built-in data types:

Numeric Types:
• int – whole numbers (10, -5)
• float – decimal numbers (3.14, -0.5)
• complex – complex numbers (2+3j)

Text Type:
• str – string values ("Hello", 'Python')

Sequence Types:
• list – ordered, mutable ( [1, 2, 3] )
• tuple – ordered, immutable ( (1, 2, 3) )
• range – sequence of numbers ( range(5) )

Mapping Type:
• dict – key-value pairs ( {"name": "Sumedh", "age": 20} )

Set Types:
• set – unordered collection of unique items ( {1, 2, 3} )
• frozenset – immutable set

Boolean Type:
• bool – True or False

Binary Types:
• bytes, bytearray, memoryview

3. Type Conversion
Convert values using built-in functions:
• int(), float(), str(), list(), tuple(), set()
4. Checking Data Type
Use the type() function:
• type(10) → int
• type("Hello") → str

5. Dynamic Typing
Variables can change their type at runtime:
x = 10
x = "Now I'm a string"

These notes cover the basics needed for beginners learning Python.

You might also like