Example
Local and Global Variables
Local variables exist only inside functions. Global ones are accessible everywhere.
7 results
Example
Local variables exist only inside functions. Global ones are accessible everywhere.
Quiz
Free beginner quiz on Python variable scope: 15 questions on local and global variables, the global and nonlocal keywords, and nested functions.
Quiz
Free beginner quiz on Python variables: 15 questions on naming, assignment, data types, type conversion and scope, with instant answers.
Example
The global keyword allows modifying a global variable inside a function.
Challenge
…assigns to fuel_kg inside the function, creating a local variable and leaving the global fuel unchanged. Predict the last line, compare both values, fix it by returning the total, then write a…
Article Python Fundamentals
Learn Python variables and data types - the building blocks of programming. Discover how to store numbers, text, and complex data structures effectively while following best practices for clean and…
Article Python Fundamentals
…greet_crew is the name. The rules are the same as for variable names: lowercase letters, words joined with underscores, no spaces, and it can't start with a number. The parentheses () are where inputs…