Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Python to start executing code from a given line

Tags:

python

I am completely new to Python, just learning strings and variables at the moment. I know you can put a "#" before code to comment it, but is there an option for Python to completely ignore part of the code and start working from the lines after this code?

For example:

old_price = 30
new_price = 25
difference = old_price - new_price

name = "John Smith"
age = 15
print(name, age)

I would like the code to start working from the line name="John Smith", without having to comment the first 3 lines.

like image 743
Scavenger23 Avatar asked Mar 04 '26 23:03

Scavenger23


1 Answers

You can use multiline strings to comment the whole block, not having to put # in each line:

"""
old_price = 30
new_price = 25
difference = old_price - new_price
"""
name = "John Smith"
age = 15
print(name, age)
like image 160
Diego Palacios Avatar answered Mar 06 '26 13:03

Diego Palacios



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!