2. Syntax and Types#
This chapter builds the basic vocabulary of Python programs: names, values, operators, and types.
Variables and assignment
Operators and expressions
Basic scalar types
Collection type overview
Chapter Video
This overview introduces numeric data, arithmetic operators, comparisons, and basic type conversion.
Python Tutorial for Beginners 3: Integers and Floats - Working with Numeric Data (11:55) by Corey Schafer
Hosted on YouTube; property of its original creator, embedded here for educational reference only.
Learning Objectives
By the end of this chapter, you will be able to:
Create and name variables using Python assignment syntax
Use arithmetic, comparison, logical, and assignment operators
Classify values by built-in type
Convert values between compatible built-in types
Choose appropriate basic and collection types for simple data
Chapter Flow
Glossary
# |
Term |
Explanation |
|---|---|---|
1 |
Variable |
A name that refers to a value or object in a program. |
2 |
Assignment statement |
A statement that binds a variable name to a value, such as |
3 |
Naming Rules & Conventions |
Shared rules and recommended styles for variable names and other identifiers. |
4 |
Object |
A Python value with an identity, a type, and data. |
5 |
Identity |
The unique object reference Python uses to tell whether two names point to the same object. |
6 |
Alias |
A second name that refers to the same object as another name. |
7 |
Type |
The category of a value, such as |
8 |
Operator |
A symbol or word that performs an operation, such as |
9 |
Operand |
A value that an operator works on. |
10 |
Expression |
A piece of code that evaluates to a value. |
11 |
Type conversion |
The process of changing a value from one type to another. |
12 |
Type hint |
An annotation that records the expected type of a variable, parameter, or return value. |
13 |
Mutable |
Describes an object whose contents can be changed after creation. |
14 |
Immutable |
Describes an object whose contents cannot be changed after creation. |
15 |
List |
An ordered, mutable collection of values. |
16 |
Tuple |
An ordered, immutable collection of values. |
17 |
Dictionary |
A mutable collection that stores key-value pairs. |
18 |
Set |
A mutable collection that stores unique values without a fixed order. |
19 |
Boolean |
A type with two possible values: |
20 |
Truthy |
Describes a value that behaves like |
21 |
Falsy |
Describes a value that behaves like |
22 |
Reassignment |
Binding an existing variable name to a different object; the old object itself is not changed. |
23 |
Mutation |
Changing the contents of an object in place, such as appending to a list, so every name that refers to it sees the change. |
24 |
Dynamic typing |
Python’s approach of determining a variable’s type at run time from the value assigned, so you do not declare types. |
25 |
Floor division |
The |
26 |
Modulus operator |
The |
27 |
Membership operator |
The |
28 |
Short-circuit evaluation |
Evaluation of |
29 |
Operator precedence |
The rules that decide which operations in an expression are evaluated first, such as |
30 |
Type casting |
Explicit conversion that you perform by calling a type constructor, such as |
31 |
Type coercion |
Implicit conversion that Python performs automatically, such as treating |
32 |
String |
An immutable sequence of characters written in quotes, such as |
33 |
Concatenation |
Joining strings end to end with the |
34 |
Escape sequence |
A backslash followed by a character, such as |
35 |
Indexing |
Accessing one item of a sequence by its position in square brackets, starting from 0, such as |
36 |
Slicing |
Extracting part of a sequence with |