0
Greetings all please I want to ask something
What's the meaning of this signs in python [ are this one same with parentheses ; < class > : == Ist1,Ist2 ** eg 3*1**3 means What's the difference between// and /
6 Antworten
+ 1
Absolutely, I understand that my previous response might have been a bit advanced. Consider it as a starting point or a nudge in the right direction. Each symbol and concept I mentioned plays a unique role in Python, and understanding them will become easier as you progress in your course.
In the meantime, feel free to explore these concepts at your own pace. Searching online or utilizing resources like Python documentation can be incredibly helpful. Remember, curiosity and patience are key in learning programming. You’ll encounter these symbols and their applications naturally as you continue your studies.
+ 2
In Python:
• [] denotes a list or index operation. For example, [10, 20, 30][1] returns 20.
• ; is used to separate multiple statements on a single line. For instance, len([1, 2, 3]); print("hello") outputs 3 and hello. (not recommended)
• <class 'type'> indicates the type of a class. For example, defining class MyClass: pass and then using type(MyClass) returns <class 'type'>.
• : is used to separate the header of a compound statement from its body. Example: if condition: action() executes action() if condition is true.
• == compares two values for equality. a == b returns True if a and b are equal, otherwise False.
• (item1, item2) creates a tuple, which is an immutable sequence. For example, lst1, lst2 implies a tuple containing lst1 and lst2.
Differences between // and /:
• / is used for division, returning a float.
• // is the floor division operator, returning the largest possible integer that is less than or equal to the algebraic quotient.
+ 2
Per Bratthammar ,
One tweak. Floor division // returns float if either operand is float, and it rounds toward negative infinity.
print(5 // 2) # 2
print(5.0 // 2) # 2.0
print(-5 // 2) # -3
+ 1
Thanks you sir😊😊
+ 1
Hi, Rain !
Thanks for the tweak! You’re right, // does return a float if any operand is a float, rounding toward negative infinity—a subtle but important point.
Similarly, % with floats keeps the precision, reflecting Python’s consistency in handling numeric operations. It’s these nuances that make Python both interesting and challenging.
Appreciate the insight!
0
Thank you Mr Per Bratthammar
Am still in coding foundation and your answer is difficult for me to understand can you please break it down in a beginner level