Python Forum
The of ( : ) what does it do?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
The of ( : ) what does it do?
#4
You guessed wrong. In "protein: Nutrient = Nutrient(name="Protein")" the colon is used in a type hint, not in a dictionary.

protein is a variable. It is assigned the value Nutrient(name="Protein"). The assignment has a type hint telling the reader that Nutrient(name="Protein") returns an instance of class "Nutrient".

variable : type_hint = value
protien : Nutrient = Nutrient(name="Protein")

The code does exactly the same thing if you leave the type hint out.

protien = Nutrient(name="Protein")
Frankduc, ibreeden, fracjackmac like this post
Reply


Messages In This Thread
The of ( : ) what does it do? - by Frankduc - Jul-30-2022, 02:44 PM
RE: The of ( : ) what does it do? - by deanhystad - Jul-30-2022, 05:11 PM
RE: The of ( : ) what does it do? - by Frankduc - Jul-30-2022, 05:48 PM
RE: The of ( : ) what does it do? - by deanhystad - Jul-30-2022, 09:06 PM
RE: The of ( : ) what does it do? - by mHosseinDS86 - Jul-31-2022, 09:33 AM
RE: The of ( : ) what does it do? - by ndc85430 - Jul-31-2022, 10:16 AM
RE: The of ( : ) what does it do? - by Frankduc - Jul-31-2022, 11:48 AM
RE: The of ( : ) what does it do? - by DeaD_EyE - Jul-31-2022, 03:31 PM
RE: The of ( : ) what does it do? - by Frankduc - Jul-31-2022, 03:57 PM
RE: The of ( : ) what does it do? - by deanhystad - Jul-31-2022, 05:22 PM
RE: The of ( : ) what does it do? - by Frankduc - Jul-31-2022, 06:35 PM
RE: The of ( : ) what does it do? - by deanhystad - Aug-01-2022, 03:50 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020