Click here to Skip to main content
15,901,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This syntax is let you know how many characters in "Hello world

text = 'Hello World'
   print(len(text))


& this one is to check what type of operands

text = 'Hello World'
    print(type(text)) 


"I understand the concepts mentioned above but struggle to decipher the meaning of the following code, which is built upon the principles discussed earlier."

What I have tried:

text = 'Hello World'
print len(type(text))
Posted
Comments
Mike Hankey 6-May-24 10:15am    
Start in and work out; example) type(text) returns "string" => len("string") = 5

The len operator gives the length of any object. However a 'type' does not have a length as such, as it is a conceptual item, rather than an actual object.
 
Share this answer
 
Look at the code you want to "decypher":
Python
text = 'Hello World'
print len(type(text))
That's easy to work out: it will give you and error because you are missing the compulsory brackets around the parameters to the print function. To get it to run, you need to add them:
Python
text = 'Hello World'
print(len(type(text)))
And even then, as Richard has said, what type returns doesn't have a length - it's a "description of what an object can do and what properties it can have" so again, you will get an error message. It's the same as asking "What colour is a car?" - that's not a valid question because not all cars are the same colour: "this car" is green, "that car" is red, "my car" is grey, "your car" is black.
 
Share this answer
 
Comments
Richard MacCutchan 6-May-24 11:24am    
Well you are wrong there, my car is actually silver. :))
OriginalGriff 6-May-24 11:45am    
"Shiny Grey" :D
Pete O'Hanlon 6-May-24 11:47am    
If it's a Nissan, they probably call it something like Sea Mist.
OriginalGriff 6-May-24 12:28pm    
Back in the 80's, my PM ordered his new company Vauxhall Cavalier in "Arctic Fox" because it sounded cool. Or "Pink" as everyone else called it when it arrived ... :laugh:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900