CARVIEW |
Select Language
HTTP/1.1 301 Moved Permanently
Date: Wed, 15 Oct 2025 23:47:39 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.3.33
Vary: Accept-Encoding
X-Powered-By: PHP/7.3.33
Set-Cookie: PHPSESSID=4748bd974e27e7fcddf1a80772a851d4; path=/
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
Pragma: no-cache
X-Redirect-By: WordPress
Location: https://geek-university.com/the-pass-statement/
Referrer-Policy:
Content-Length: 0
Content-Type: text/html; charset=UTF-8
HTTP/1.1 200 OK
Date: Wed, 15 Oct 2025 23:47:39 GMT
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.3.33
Vary: Accept-Encoding
X-Powered-By: PHP/7.3.33
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Link: ; rel="https://api.w.org/"
Link: ; rel="alternate"; type="application/json"
Link: ; rel=shortlink
Content-Encoding: gzip
Referrer-Policy:
Content-Length: 16005
Content-Type: text/html; charset=UTF-8
The pass statement | Python#
- CCNA online course
- Linux online course
- VMware ESXi online course
- Nmap online course
- MySQL online course
- Raspberry Pi online course
- Apache HTTP Server course
- VMware Player online course
- Splunk online course
- SQL online course
- Oracle VirtualBox online course
- Python online course
- Asterisk course
- VMware Workstation Player course
- Process Explorer course
- Pillow online course
- Create a web crawler in Python
- A short introduction to…
The pass statement
The pass statement in Python usually serves as a placeholder to ensure that the block has at least one statement. It is a null operation, which means that nothing happens when it executes. In some cases, however, it can be used instead of the continue statement, since it allows the completion of the code inside the if statement in which it appears.
Consider the following example:
for i in range(1,11): if i==5: pass print('Number 5 encountered.') print(i)
The output:
>>> 1 2 3 4 Number 5 encountered. 5 6 7 8 9 10 >>>
Notice how the Number 5 encountered message was printed. If continue was used instead of the pass statement, the print statement inside the if statement would not execute.
Another example:
x = 0 for currentLetter in 'Hello world!': if currentLetter == 'l': pass x += 1 print('This is the',x,'instance of the letter l.') print('The current letter is', currentLetter) print('There have been',x,'instances of letter l.')
The code above calculates how many times the letter l appears in the Hello world! string and produces the following output:
>>> The current letter is H The current letter is e This is the 1 instance of the letter l. The current letter is l This is the 2 instance of the letter l. The current letter is l The current letter is o The current letter is The current letter is w The current letter is o The current letter is r This is the 3 instance of the letter l. The current letter is l The current letter is d The current letter is ! There have been 3 instances of letter l. >>>
Python course
- Introduction
- Python overview
- Install Python on Windows
- Install Python on Linux
- Add Python to the Windows Path
- Run Python code
- Interactive prompt
- IDLE editor
- Command line
- Help mode
- Basic programs
- Write your first program
- Use comments
- What are variables?
- Variable data types
- Variable names
- Numeric variables
- Strings
- Get the current date and time
- Operators overview
- Arithmetic operators
- Comparison operators
- Logical operators
- Assignment operators
- Membership operators
- Identity operators
- Conditional statements
- The if statement
- Get user input
- The if...else statement
- The if...elif statement
- Nested if statements
- Use logical operators
- Loops
- The for loop
- Use for loop with the range() function
- The break statement
- The continue statement
- The pass statement
- Use else statement in loops
- The while loop
- Nested loop statements
- Errors
- Types of errors
- Syntax and logical errors
- The try...except statements
- The try...except...else statements
- The try...except...finally statements
- Catch specific exceptions
- Raise exception
- Nest exception handling statements
- Modules
- What are modules?
- Import modules
- Find files on disk
- Display module content
- Strings
- What are strings?
- Escape characters
- Access individual characters
- String functions
- Search strings
- Concatenating strings
- Lists, sets, tuples, dictionaries
- What are lists?
- Modify lists
- Loop through a list
- Check whether a value is in a list
- Sorting lists temporarily
- Sorting lists permanently
- Obtaining the list length
- What are sets?
- What are dictionaries?
- Add new key-value pair to a dictionary
- Modify a value in a dictionary
- Delete a key-value pair in a dictionary
- Loop through a dictionary
- What are tuples?
- Looping over a tuple
- Working with files
- How to read and write files
- Read a file
- Read and write – with statement
- Make a list of lines from a file
- Functions
- What are functions?
- Return statement
- Positional arguments
- Keyword arguments
- Default values for parameters
- Flexible number of arguments
- Variable scopes