Skip to content

hedeesaa/PyQuestions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

PyQuestions

It started to post some Python Questions on my Instagram stories, just for fun! But as I saw people's enthusiasm for answering questions, I decided to gather these questions here too, with their solutions.

It's just for fun, good luck! 🍷

PS: I got the idea from Lydia Hallie, you should definitly check her repo if you are a JS fan! ❤️


Questions

1. What's the output?

def hello_world():
    return "Hello", "World!"

def good(s1, s2):
    return f"{s1} Good {s2}"

print(good(hello_world()))
  • A: Error
  • B: "Hello Good World"
Answer

Answer: A

Python returns objects in Tuple!
So the output of the hello_world() is the Tuple of ("Hello","World"). When we use it as a input for good() function, it will act as the first argument of the function which means s1.


2. What's the output? If user types "Hedeesaa".

print(len(input("What is your name?")))
  • A: Error
  • B: 0
  • C: 18
  • D: 8
Answer

Answer: D

Python executes functions from inner to outter!
So input("What is your name?") will be run first, then user enters "Hedeesaa".
After that method len() will be run over "Hedeesaa". So len() will show the length of "Hedeesaa" which is 8 :)


About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages