Software engineering and personal development

Category: Science & Tech (Page 8 of 35)

How to Quickly Simply “if” Statements in Python

There can be cases when we want to check whether a value is equal to one of the multiple other values.

One way that someone may start using is using or and adding multiple checks. For example, let us say that we want to check whether a number is 11, 55, or 77. Your immediate response may be to do the following:

 m = 1
 ​
 if m == 11 or m == 55 or m == 77:
     print("m is equal to 11, 55, or 77")

There is fortunately another quick way to do that.

Continue reading

How to Round Numbers Using Negative Numbers in Python

If you are working with many numbers in Python, you probably need to do some rounding to cut off some digits that you may not need at all.

For example, let us say that you are calculating an average salary in a company and the average number that you have found is around 54,334.218

This may not be a number that can look good in a final report that you want to submit to someone. It would help if you instead rounded it.

Continue reading

How to Quickly Split a String on the First N Occurrences in Python

brown wooden blocks on white surface
Photo by Brett Jordan on Unsplash

You have probably seen cases when you can do splits of strings into multiple parts based on a pattern that is observed in the string. For example, let us say that we want to save all the words that are part of a sentence. 

To do that, we usually try to do split the sentence into words based on the spaces that we find, such as:

Continue reading
« Older posts Newer posts »

© 2024 Fatos Morina

Theme by Anders NorenUp ↑