On 17/10/2026 19:01, John Bokma wrote:
> On 17/10/2026 18:46, Stéphane CARPENTIER wrote:
>
> [..]
>
>> With some typed languages, you can't use a variable if you didn't
>> declare it's type before. With python, you don't need to declare
>> integers and strings but you need to declare dictionaries. Why? Don't
>> know.
>
> I guess you confuse assigning a type with creating an object of a specific type.
>
>> With python, that looks easy and when I fix something, it breaks
>> something else for reasons I don't understand.
>
> I recommend to install Copilot CLI on your system and ask it to explain why your script breaks. It's quite good at explaining is my experience.
Examples:
Explain as a professional Python programmer why 1+True yields 2 and is valid
Thought for 3s
In Python, bool is a subclass of int . The two Boolean values behave numerically as False == 0 and True == 1 , so adding True to 1 is equivalent to 1 + 1 :
1 + True # 2
type(1 + True) # int
It’s valid because Python’s numeric operations accept Boolean values as integers. In application code, though, it’s usually clearer to convert or count explicitly if you intend to use a Boolean as a number.
Why do I have to declare dictionaries but can use integers and strings without declaring their type
Thought for 2s
In Python, you don’t have to declare a dictionary’s type. Python is dynamically typed: a variable name refers to an object, and the object carries its type.
count = 3 # creates an int object
message = "hello" # creates a str object
settings = {} # creates a dict object
Integers and strings have compact literal syntax ( 3 , "hello" ); dictionaries use {} or key-value pairs, such as {"theme": "dark"} . That’s creating a dictionary, not declaring its type.
Type annotations are optional and mainly help readers and static-analysis tools:
settings: dict[str, str] = {}
Can't recommend Copilot enough.
--
Static tumblelog generator: https://github.com/john-bokma/tumblelog/
Available as Python or Perl. Example tumblelog: https://plurrrr.com/