0
0
Pythonprogramming~15 mins

Built-in scope in Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Exploring Built-in Scope in Python
๐Ÿ“– Scenario: Imagine you are learning how Python finds names like functions and variables when you use them. Python first looks in your own code, then in the places it knows by default, called the built-in scope.
๐ŸŽฏ Goal: You will create a simple program to see how Python uses built-in names and how you can use your own names without changing the built-in ones.
๐Ÿ“‹ What You'll Learn
Create a variable named my_len with a list of three fruits
Create a variable named length and set it to 0
Use a for loop with variable item to count items in my_len
Print the value of length
Print the result of the built-in len function on my_len
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Understanding built-in scope helps you avoid mistakes when naming your variables and using Python's built-in functions.
๐Ÿ’ผ Career
Knowing how Python finds names is important for writing clear and bug-free code, a key skill for any programming job.
Progress0 / 4 steps
1
Create a list named my_len
Create a list called my_len with these exact items: 'apple', 'banana', and 'cherry'.
Python
Need a hint?

Use square brackets [] to create a list and separate items with commas.

2
Create a variable length to count items
Create a variable called length and set it to 0. This will hold the count of items in my_len.
Python
Need a hint?

Just write length = 0 to start counting from zero.

3
Count items in my_len using a for loop
Use a for loop with variable item to go through each item in my_len. Inside the loop, add 1 to length for each item.
Python
Need a hint?

Use for item in my_len: and inside the loop write length += 1 to add one each time.

4
Print the counted length and the built-in length
Print the value of length. Then print the result of the built-in len function called on my_len to compare.
Python
Need a hint?

Use print(length) and print(len(my_len)) to show both counts.