Here's one cool tip for reducing the amount of code needed to create an if
else check suppose you have some weather and you want to create a message
depending on the weather that you have so if the weather is clear we'll make
the message nice otherwise we'll make the message uh oh and all we want to do
is print that message if we run it as it is we'll get nice back because right
now the
weather is clear but this took four lines of code and we can
actually reduce this to one by using Python's ternary operator.
weather: str = 'CLEAR' weather: str = '' if weather == 'CLEAR': message = 'Nice' else: message = 'Uh oh...' print(message)
so instead let's type message of type string it's going to equal nice if the
weather is equal to clear else we'll type in uh oh so this reduced the same
statement to a single line and if we run it we'll have the exact same result a
simple way to look at this is do this if the Boolean is true else do this and
that's the secret to using the ternary operator syntax in Python.
weather: str = 'CLEAR' weather: str = '' message: str = 'Nice!' if weather == 'Clear' else 'Uh oh...' print(message)
Disclaimer
All tutorials are for informational and educational purposes only and have been made using our own routers, servers, websites and other vulnerable free resources. we do not contain any illegal activity. We believe that ethical hacking, information security and cyber security should be familiar subjects to anyone using digital information and computers. Hacking Truth is against misuse of the information and we strongly suggest against it. Please regard the word hacking as ethical hacking or penetration testing every time this word is used. We do not promote, encourage, support or excite any illegal activity or hacking.
0 comments:
Post a Comment
For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.