0

Can someone explain to me how this code works ? It prints numbers from 0 to 100, but I cannot understand how.

print(*range(True,ord("e")))
1
  • What don't you understand exactly? Do you understand who print works with multiple arguments? Do you understand what argument unpacking with the * operator does? Commented Mar 24, 2021 at 21:14

2 Answers 2

2

ord accepts a character and returns the ASCII code. In this case "e" returns 101. The *range is unpacking the iterable that range creates. Enabling you to print out the values from True (1) to 101 - 1.

I found this out by googling each piece of code individually. Type in "ord python" then another search was "star range python". These searches lead to information you are seeking.

Sign up to request clarification or add additional context in comments.

Comments

2
print(*range(True,ord("e")))

Firstly, print() means that we are displaying some information on the screen.

Secondly, the * indicates that there may be more than one object to be printed.

Now, think of the True as a 0. True does nothing. The ord("e") means where is e in the Unicode. It returns that number, which is 101. Now, range(start, end) means every value between the start value (0), and end value (1).

2 Comments

Why wouldn't someone just do print(*range(0,100))?
No idea. They must have their reasons but I seen none why

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.