The document provides an overview of Python programming, focusing on variables, data types, and operators. It explains how to create variables, the rules for naming them, and the dynamic typing feature of Python. Additionally, it outlines the built-in data types supported by Python, including numbers, strings, lists, tuples, sets, and dictionaries.
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 ratings0% found this document useful (0 votes)
5 views11 pages
Variables, Data Types
The document provides an overview of Python programming, focusing on variables, data types, and operators. It explains how to create variables, the rules for naming them, and the dynamic typing feature of Python. Additionally, it outlines the built-in data types supported by Python, including numbers, strings, lists, tuples, sets, and dictionaries.
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
You are on page 1/ 11
Python Programming
Variables, Data Types,
and Operators Python Variables
In Python, variables are created when you
assign a value to them. The assignment operator, which is denoted by the equal sign (=), is used to assign a value to a variable. For example, the following code creates a variable named "x" and assigns the value 5 to it Naming a Variable
A variable name must start with a letter or
the underscore character A variable name cannot start with a number A variable name can only contain alpha- numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive (age, Age and AGE are three different variables) Python is a dynamically typed language, which means that the data type of a variable is determined at runtime based on the value that is assigned to it. This is different from statically typed languages like Java, where the data type of a variable is specified explicitly in the code. Python Data Types: Python supports several built-in data types, which include
Numbers: Python supports integers, floating-point
numbers, and complex numbers. For example: Strings: Strings are used to represent text in Python. They are enclosed in single or double quotes. For example: Lists: Lists are used to store a collection of items. They are enclosed in square brackets and separated by commas. For example Tuples: Tuples are similar to lists but are immutable, which means that their contents cannot be changed after they are created. They are enclosed in parentheses and separated by commas. For example: Sets: Sets are used to store a collection of unique items. They are enclosed in curly braces or created using the set() function. For example Dictionaries: Dictionaries are used to store key-value pairs. They are enclosed in curly braces and each keyvalue pair is separated by a colon. For example: