Python · Python

Python Basics: Syntax and Data Types

Core Python syntax, variable types, and common data structures (lists, dicts, tuples) explained with a short example each.

43 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Get FlashKeepers for iPhone
What is a variable in Python?
A named container that stores a value. You assign it once and can refer to it by name throughout your code.
How do you assign a value to a variable in Python?
Use the equals sign (=). Example: name = 'Alice'
What is dynamic typing in Python?
The type of a variable is determined by the value assigned to it at runtime, and can change if reassigned.
What is the int data type in Python?
A data type for whole numbers without a decimal point. Example: x = 5
What is the float data type in Python?
A data type for numbers with a decimal point. Example: pi = 3.14
What is the str data type in Python?
A sequence of characters enclosed in quotes (single, double, or triple). Example: text = 'Hello'
What is the bool data type in Python?
A data type with only two values: True or False.
How do you create a list in Python?
Use square brackets with comma-separated values. Example: nums = [1, 2, 3]
How do you access a single element in a list?
Use the index in square brackets. Example: nums[0] returns the first element.
What is list indexing in Python?
The position of an element in a list, starting from 0 for the first element.
What is negative indexing in Python?
Using negative numbers to index from the end of a list. Example: nums[-1] is the last element.
How do you add an element to a list?
Use the append() method. Example: nums.append(4) adds 4 to the end.
How do you remove an element from a list?
Use remove() to delete by value, or pop() to delete by index. Example: nums.remove(2) or nums.pop(0)
What is a tuple in Python?
An ordered collection of elements enclosed in parentheses that cannot be changed after creation.
How do you create a tuple?
Use parentheses with comma-separated values. Example: coords = (10, 20)

28 more cards in the app