Coding Computing Coach
@CodingComputing
Making Python simple for you, by exploring the fundamentals. Tips and explanations to become code-literate in this AI age. Building @PythonResources
내가 좋아할 만한 콘텐츠
🚨 Python Testing Series 🚨 Employ testing to gamify your coding. Learn how to test code using pytest. Build a Cash Dispenser project in Test Driven style. Ongoing series of posts, see README at: github.com/CodingComputin…
🤔🚀 Comment your answers below! 👇
Do list comprehensions make your head spin? Worry not, this thread has you covered.
Answer: C. [8, 12] Solution: a and b are lists. Then there is a list comprehension that gives c. Let's analyze the list comprehension. Here is the trick to analyze list comps: 🗝️ Look for 3 things: `for`, `in`, and `if` (`if` is optional, sometimes it may not be there) +
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python doesn't read your mind (or your strings)
Answer: B. 55 Solution: See the data types! a and b are both strings, with the value "5". So, python treats them as characters, not numbers. Now, for string operands, the `+` operator joins them. So, a+b joins the strings '5' and '5', to '55'. Hence, 55 is printed.
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Tuples are immutable, so some methods just don't make sense for tuples.
Answer: D. Error Solution: (5, 10, 20) is a tuple. Tuples have no `insert` method, hence it's an Error. More generally, tuples are immutable. For a tuple once formed, you cannot modify it. So, an insert method cannot exist for tuple anyway.
Comment below the output! 😃👇
Users are really innovative when it comes to breaking software.
Convert strings to integer
Answer: C Solution: x is an int, and y is a string. The call to `int(y)` obtains the integer value from y (string "5") ie the integer 5. Thus, int(y) is integer 5. x is also integer 5. The printed value is their sum, ie 10. int is a handy function for converting to integer.
Comment below the output! 😃👇
It says what you want to hear.
“oh you are absolutely right, I see the problem now” chatgpt you didn’t see sh!t 😭
Some python methods do their work but give None
Answer: A Solution: Essentially we are calling func and printing it's return value. So let's work out what func is doing. lst, lst2 = [7], [7] is a tuple assignement lst is assigned [7], and lst2 is assigned [7] lst3 = lst *2 repeats lst twice, ie, [7, 7], assigns to lst3 +
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
It's a choice, but not between these 2. It's a choice between asking a half-baked question and a high-effort question. The more you think about the problem, the better question you can ask. The better question you ask, the better answer you get.
Don't start writing code until you're clear about what you're set out to do.
`*` operator with lists repeats their contents. Very literally:
Answer: Assuming [[]]*3 on the first line, then [[1], [1], [1]] (which is like option D but not the same). Solution: Let's see what's happening here. As you would recall, `*` of list and int produces repetitions of the list. Therefore, [[]]*3 repeats [] 3 times in a new list +
Comment below the output! 😃👇
United States 트렌드
- 1. #BTCCBestCEX 6,912 posts
- 2. Falcons 37.1K posts
- 3. Expedition 33 178K posts
- 4. Kyle Pitts 18.1K posts
- 5. #TheGameAwards 386K posts
- 6. Bucs 23.2K posts
- 7. #heatedrivalry 33.5K posts
- 8. Todd Bowles 5,423 posts
- 9. GOTY 58.9K posts
- 10. ilya 35.1K posts
- 11. Baker 22.8K posts
- 12. Mega Man 34.1K posts
- 13. Kirk Cousins 5,871 posts
- 14. Mike Evans 10.4K posts
- 15. #KeepPounding 2,171 posts
- 16. Geoff 63.3K posts
- 17. Bijan 7,221 posts
- 18. Leon 177K posts
- 19. Sonic 83.5K posts
- 20. NFC South 3,271 posts
내가 좋아할 만한 콘텐츠
-
Tom Mitchell
@imtommitchell -
tom ッ
@tom_antok -
Benjamin Bennett Alexander
@RealBenjizo -
Python Coding
@clcoding -
Akshay 🚀
@akshay_pachaar -
IA Revolução
@IArevolucao -
Raul Junco
@RaulJuncoV -
Mike Driscoll
@driscollis -
Professor the Hunter
@bughuntar -
Afiz ⚡️
@itsafiz -
Data Science Tutorials
@DataSciencetut -
Python Developer
@Python_Dv -
Pau Labarta Bajo
@paulabartabajo_ -
Security Trybe
@SecurityTrybe -
Python Programming
@PythonPr
Something went wrong.
Something went wrong.