Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →In Python, a variable is a name bound to an object, and the equals sign (=) assigns a value to that name. A type tells Python what kind of object it is—such as a number, text, or collection—and what operations make sense for it. Once you understand assignment and the difference between changeable and unchangeable objects, common beginner code becomes much easier to follow.
What is a variable in Python?
A variable is best understood as a label attached to an object, not a box that permanently contains a value. In count = 3, Python binds the name count to the integer object 3. The equals sign assigns a value to a variable name; it does not mean that the name and object are the same thing. See the Python Tutorial’s introduction.
As an Amazon Associate I earn from qualifying purchases.
count = 3
count = 4
The second assignment binds count to a different integer object. The name can be assigned again, and Python does not require a separate declaration before assignment. But a name must have a value before you use it: trying to read an unassigned name raises NameError.
Assignment is different from comparison
Use one equals sign, =, to assign a value. In a condition, two equals signs, ==, test whether values are equal:
#1 Best Overall
score = 10 # assign 10 to score
print(score == 10) # test whether score equals 10
What are the basic data types in Python?
A type describes an object’s kind and helps determine what you can do with it. These built-in types cover many beginner tasks:
int: whole-number values, such as7.float: numbers represented with a fractional part, such as2.5.str: text, written inside quotes, such as'hello'.list: an ordered, changeable collection, such as[3, 5, 8].tuple: an ordered sequence whose item positions cannot be reassigned, such as(3, 5, 8).set: an unordered collection of unique elements, such as{3, 5, 8}.dict: a collection of key:value pairs, such as{'name': 'Mina'}.
Numbers: int and float
Python distinguishes integer and floating-point values. Ordinary division with / produces a float, even when the result is a whole number. Floor division with // rounds the quotient down to the nearest integer, and % gives the remainder.
print(7 / 2) # 3.5
print(7 // 2) # 3
print(7 % 2) # 1
Text: str
A string is a sequence of characters. You can read a character by its index or take a slice of the text, but you cannot replace one character in the existing string. To change the text, create a new string and assign it to a name.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsRank #2
greeting = 'hello'
print(greeting[0]) # h
print(greeting[1:4]) # ell
greeting = 'j' + greeting[1:] # a new string: jello
Collections: sequences, sets, and dictionaries
Collections group multiple values, but they serve different purposes. Lists and tuples are sequences: their elements have positions, so you can access them by index. Sets are for unique membership rather than a stable position or display order. Dictionaries map keys to values, so you look up a value by its key rather than a numeric index.
Choose based on what the data needs to do, not on a universal ranking:
- Use a
listfor an ordered sequence you expect to change. - Use a
tuplewhen the sequence’s item positions should not be reassigned. - Use a
setwhen you need unique elements or want to check membership. - Use a
dictwhen you need to retrieve values using meaningful keys.
Lists and tuples can contain repeated values. Sets keep unique elements, so adding a duplicate does not create another distinct member. A dictionary stores values under keys, which must be unique within that dictionary.
What is the difference between a list and a tuple?
Both lists and tuples are ordered sequences, but a list is mutable and a tuple is immutable. Mutable means the object can be changed in place; immutable means it cannot. You can replace a list item or append an item without making a new list. You cannot assign a different value to an individual tuple position.
The Tool Desk
Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →colors = ['red', 'green']
colors[1] = 'blue'
colors.append('gold')
print(colors) # ['red', 'blue', 'gold']
point = (4, 9)
# point[0] = 5 # raises TypeError
A one-item tuple needs a trailing comma. Without the comma, parentheses simply group the value:
single_value = ('hello',) # tuple
not_a_tuple = ('hello') # string
Immutability applies to the object itself, not automatically to everything it refers to. A tuple can contain a mutable object such as a list. The tuple’s reference to that list cannot be replaced by item assignment, but the list can still be changed:
group = (['red', 'green'], 'colors')
group[0].append('blue')
print(group) # (['red', 'green', 'blue'], 'colors')
The Python data model documentation describes mutability as a property of an object’s type; an immutable container can refer to a mutable object.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Does assigning a list copy it?
No. Assignment binds another name to the same list object. If either name is used to mutate that list, the change is visible through both names.
colors = ['red', 'green']
other_name = colors
other_name.append('blue')
print(colors) # ['red', 'green', 'blue']
This behavior is called aliasing: multiple names refer to one object. It is useful when shared access is intended, but can be surprising if you expect a separate list.
Best Value
Make a shallow copy when you need a separate outer list
A slice such as colors[:] creates a shallow copy of the outer list. Adding or replacing an item in one outer list will not change the other. However, if the list contains nested mutable objects, those inner objects are still shared.
original = ['red', 'green']
copy = original[:]
copy.append('blue')
print(original) # ['red', 'green']
print(copy) # ['red', 'green', 'blue']
How to choose a type for a beginner program
Start with the operations you need. If you are storing one value, use a number or string. If you need several values in order, use a list when they may change and a tuple when their positions should stay fixed. Choose a set when duplicates should collapse into one membership, and a dictionary when each value should be found by a key.
For a fuller reference, the official Python Tutorial says it is aimed at programmers new to Python rather than people entirely new to programming. It covers more than this introduction, so beginners without programming experience may need to take its examples slowly and look up unfamiliar terms.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




