Quick Python | Using Underscores as Digit Separators in Python | Shorts

Published: 24 May 2021
on channel: choobtorials
231
9

In this Quick Python tutorial, we see how underscores can be used to help improve readability when writing long numeric values.

=====

In Python, as well as many other programming languages, commas cannot be used when writing numbers.

In this example, the commas will cause Python to treat these as separate values and pack them into what’s called a tuple.

So in place of commas, we can use underscores to visually separate the digits into groups. This is a common feature in many modern languages and can be used to help improve the readability of long numeric values.

So in this updated example, underscores are now being used as separators. And when this gets evaluated, the underscores are ignored, and the value is interpreted as having a numeric type.

=====

Twitter:   / choobtorials  

#PythonTips


On this page of the site you can watch the video online Quick Python | Using Underscores as Digit Separators in Python | Shorts with a duration of hours minute second in good quality, which was uploaded by the user choobtorials 24 May 2021, share the link with friends and acquaintances, this video has already been watched 231 times on youtube and it was liked by 9 viewers. Enjoy your viewing!