🔹 Assignment Set: Python Variables & Literals (Beginner Level)
1) Simple Variable Assignment
Write Python code to do the following:
Create a variable called age and assign your age to it.
Create a variable called name and assign your name (as a string) to it.
Example expected output (your values will vary):
2) Reassigning Variables
Create a variable city and assign it any city name (string).
Then change the value of city to a different city and print it each time.
Expected pattern:
city = "Toronto"
print(city)
city = "Vancouver"
print(city)
3) Multiple Variable Assignment
In one line, assign values to three variables:
Then print all three variables.
4) Numeric Literals
Create these variables:
Print each one.
5) String Literals
Create variables holding:
A single-quoted string (e.g., 'Python')
A double-quoted string (e.g., "Beginner")
Print both.
6) Boolean Literals
Create two variables:
Print both variables and their types.
7) Special Literal: None
Create a variable result and assign None to it.
Use an if statement to check if result is None, and print a message like:
8) Collection Literals
Create and print the following literals:
A list of 3 numbers: [1, 2, 3]
A tuple of 3 strings: ("a", "b", "c")
A set of 3 values: {10, 20, 30}
A dictionary with 2 key–value pairs: {"name": "Alice", "age": 25}
9) Binary, Octal & Hex Literals
Create variables:
Print them. (They should all print the number 10.)
10) Simple Expressions with Variables
Create two numeric variables a and b.
Assign them values like 3 and 7, then:
Here are 10 more very basic assignments on Python Variables & Literals. These stay strictly foundational.
11) Swap Two Variables
Create two variables:
Swap their values and print them.
Expected output:
12) Type Checking
Create variables:
Print the type of each variable using type().
13) String Concatenation
Create two string variables:
Combine them into one variable called full_name with a space in between.
Print the result.
Expected:
14) Length of a String
Create a variable:
Print the number of characters in the string.
15) Convert Data Types
Create:
Convert it into an integer and print:
16) Using Escape Characters
Create a string that prints:
Use \n inside a single string literal.
17) Boolean from Comparison
Create:
Store the result of a > b in a variable called result and print it.
18) Update a Variable
Create:
Increase its value by 1 and print it.
Expected:
19) Check Variable Identity
Create two variables:
Use is operator to check if x and y refer to the same object.
Print the result.
20) Create a Simple Profile Dictionary
Create a dictionary variable profile with keys:
Print the dictionary.
Example structure:
canvil:
333f6c7d-6876-4f7e-b6ad-1bdb2233f5c1