7 Little Things That Can Tell You A Lot About Someone7

Author : denidodo2
Publish Date : 2021-04-07 17:54:44
7 Little Things That Can Tell You A Lot About Someone7

These days I have a newfound pastime — reading Python documentation just for fun! When you read something at leisure, you tend to notice interesting tidbits that you would have missed otherwise. So, here is the list of tidbits that made me go “Oh! You can do that in Python?”
1. Function Attributes
Similar to how you can set attributes of classes and objects, you can also set attributes to functions.

We have set the attributes ‘optional_return’ in line 10 and ‘is_awesome’ in line 11. We have accessed those attributes outside of the function later in lines 19 & 20. The output of the code will be:
Final answer is 2197
Show calculations --> 13
Is my function awesome? --> Yes, my function is awesome.
This comes in handy when you want the option to retrieve some intermediate variable, but not explicitly return it with the return statement every time the function is called. Also note that attributes can be set from inside the function definition or from outside the function definition.
2. For-else loop
In Python, you can add an else clause to a for loop. The else clause will be triggered only if no break statement was encountered within the body of the loop during execution.

All elements at least 3 letters long
Notice that the else is indented at the level of for and not at the level of if. Here, no element has length shorter than 3. So, the break statement will never be encountered. Hence, the else clause will get triggered (after the for loop is executed) and print the output shown above.
One could argue that this could be achieved using a separate variable that keeps track of whether the break statement was encountered. And perhaps it would also be less confusing for the next person reading the code. Still, it’s good to know, I guess.
3. Separators for ‘int’
It’s hard to distinguish visually between integers like 10000000 and 100000000 (are they even different numbers?). We can’t use commas here in Python like we use them in English because Python will interpret it as a tuple of multiple integers.
Python has a very convenient way of dealing with this: we can use underscore as a separator to improve readability. Thus, 1_000_000 will be interpreted as a single int.

True
4. eval() and exec()
Python has the ability to dynamically read a string and treat it like a piece of Python code. This is achieved using eval() and exec() functions (‘eval’ is for evaluating expressions and ‘exec’ is for executing statements).

b = 5
c is 9
In line 3, eval() function will read the input string as a Python expression, evaluate it, and assign the result to the variable ‘b’. In line 6, exec() function will read the input string as a Python statement and execute it.
You can even pass dynamically created strings to these functions. You could, for example, create 1000 variables with names x_0, x_1, …, x_999 without having to write each of those variable declarations manually in your code. This might look like it’s a completely pointless feature, but it’s not.
In the broader context of programming in general, not just Python, the use of eval/exec is incredibly powerful because it allows you to write dynamic code that uses information available at runtime to solve problems which cannot even be expressed at compile time. […] exec is literally a Python interpreter embedded inside Python, so if you have a particularly hard problem to solve, one of the ways you can solve it is to write a program to *write a program to solve it*, then use exec to run that second program.
You can read more of this beautiful explanation by Steven D’Aprano.
5. Ellipsis
Ellipsis or ‘…’ is a built-in constant of Python similar to built-in constants like None, True, False, etc. It can be used in different ways including, but not limited to:
5.1 Placeholder for unwritten code
Similar to pass, Ellipsis can be used as a placeholder when the code is not fully written, but requires some placeholder for syntactic accuracy

5.2 Alternative to ‘None’
None is the usual choice when one wants to denote an empty input or return. But sometimes None can be one of the expected inputs or returns of a function. In that case Ellipsis can serve as the placeholder.

The function nth_odd() calculates the nth odd number, given n. The function original_num() calculates the original number n, given the nth odd number. Here, None is one of the expected inputs to the function original_num() so we can’t use it as the default placeholder for the argument m. The output of the code will be:
This function needs some input
Non integer input provided to nth_odd() function
9 is 5th odd number
16 is not an odd number
5.3 Array slicing in NumPy
NumPy uses Ellipsis to slice an array. The following code shows two equivalent ways of slicing a NumPy array:

[ 0  2  4  6  8 10 12 14]
[ 0  2  4  6  8 10 12 14]
Thus, ‘…’ signifies that there are as many ‘:’s as needed.
Boolean value of Ellipsis
In contrast to None (whose Boolean values is False), the Boolean value of Ellipsis is taken to be True.
TL;DR

Is my function awesome? --> Yes, my function is awesome.
This comes in handy when you want the option to retrieve some intermediate variable, but not explicitly return it with the return statement every time the function is called. Also note that attributes can be set from inside the function definition or from outside the function definition.
2. For-else loop
In Python, you can add an else clause to a for loop. The else clause will be triggered only if no break statement was encountered within the body of the loop during execution.

All elements at least 3 letters long
Notice that the else is indented at the level of for and not at the level of if. Here, no element has length shorter than 3. So, the break statement will never be encountered. Hence, the else clause will get triggered (after the for loop is executed) and print the output shown above.
One could argue that this could be achieved using a separate variable that keeps track of whether the break statement was encountered. And perhaps it would also be less confusing for the next person reading the code. Still, it’s good to know, I guess.
3. Separators for ‘int’
It’s hard to distinguish visually between integers like 10000000 and 100000000 (are they even different numbers?). We can’t use commas here in Python like we use them in English because Python will interpret it as a tuple of multiple integers.
Python has a very convenient way of dealing with this: we can use underscore as a separator to improve readability. Thus, 1_000_000 will be interpreted as a single int.

True
4. eval() and exec()
Python has the ability to dynamically read a string and treat it like a piece of Python code. This is achieved using eval() and exec() functions (‘eval’ is for evaluating expressions and ‘exec’ is for executing statements).

b = 5
c is 9
In line 3, eval() function will read the input string as a Python expression, evaluate it, and assign the result to the variable ‘b’. In line 6, exec() function will read the input string as a Python statement and execute it.
You can even pass dynamically created strings to these functions. You could, for example, create 1000 variables with names x_0, x_1, …, x_999 without having to write each of those variable declarations manually in your code. This might look like it’s a completely pointless feature, but it’s not.
In the broader context of programming in general, not just Python, the use of eval/exec is incredibly powerful because it allows you to write dynamic code that uses information available at runtime to solve problems which cannot even be expressed at compile time. […] exec is literally a Python interpreter embedded inside Python, so if you have a particularly hard problem to solve, one of the ways you can solve it is to write a program to *write a program to solve it*, then use exec to run that second program.
You can read more of this beautiful explanation by Steven D’Aprano.
5. Ellipsis
Ellipsis or ‘…’ is a built-in constant of Python similar to built-in constants like None, True, False, etc. It can be used in different ways including, but not limited to:
5.1 Placeholder for unwritten code
Similar to pass, Ellipsis can be used as a placeholder when the code is not fully written, but requires some placeholder for syntactic accuracy

5.2 Alternative to ‘None’
None is the usual choice when one wants to denote an empty input or return. But sometimes None can be one of the expected inputs or returns of a function. In that case Ellipsis can serve as the placeholder.

In summary, the interesting features I found thus far are:
Function Attributes: Assign attributes to functions just like objects
For-else loop: To keep track of whether the loop was executed without break statement
Separators for int: 32_534_478 is an int
eval() and exec(): read strings as Python code and run it
Ellipsis: A versatile built-in constant.
Parting Words
Python is not just a useful language, but also a really interesting one. We are all busy in our lives, but it doesn’t hurt to get to know the language better for its own sake. I would love to know about some Easter-eggs that you might have found.
https://www.getrevue.co/profile/Watch-Legacies-Season3Episode9
https://www.getrevue.co/profile/Last-Man-Standing-S9-E14
https://www.getrevue.co/profile/Meet-the-Richardsons-S2-E1
https://www.getrevue.co/profile/Everythings-Gonna-Be-Okay-S2E1
https://www.getrevue.co/profile/Station-19-Season4Episode10-free
https://www.getrevue.co/profile/Watch-Walker-Season1Episode8
https://www.getrevue.co/profile/LawOrderSpecialVictimsUnit-22-10
https://www.getrevue.co/profile/Watch-Young-Sheldon-S4-E13
https://www.getrevue.co/profile/FullSeries-Greys-Anatomy-S17-E11
https://www.getrevue.co/profile/Watch-Manifest-Season3Episode2
https://www.getrevue.co/profile/Clarice-Season1Episode7
https://www.getrevue.co/profile/Made-For-Love-Season1Episode4
https://www.getrevue.co/profile/Law-Order-Organized-Crime-S1E2
https://www.getrevue.co/profile/Series-Mom-Season8Episode13
https://www.getrevue.co/profile/KeepingUpwiththeKardashians20-04
https://www.getrevue.co/profile/FullSeries-Greys-Anatomy-S17-E11/issues/hd-series-grey-s-anatomy-season-17-episode-11-hd-online-full-episodes-issue-1-545520
https://www.getrevue.co/profile/Watch-Legacies-Season3Episode9/issues/hd-series-legacies-season-3-episode-9-hd-online-full-episodes-issue-1-545525
https://www.getrevue.co/profile/Station-19-Season4Episode10-free/issues/hd-series-station-19-season-4-episode-10-hd-online-full-episodes-issue-1-545534
https://www.getrevue.co/profile/Watch-Walker-Season1Episode8/issues/hd-series-walker-season-1-episode-8-hd-online-full-episodes-issue-1-545541
https://www.getrevue.co/profile/Watch-Young-Sheldon-S4-E13/issues/hd-series-young-sheldon-season-4-episode-13-hd-online-full-episodes-issue-1-545562
https://www.getrevue.co/profile/LawOrderSpecialVictimsUnit-22-10/issues/hd-series-law-order-special-victims-unit-season-22-episode-10-hd-online-full-episodes-issue-1-545552
https://www.getrevue.co/profile/Watch-Manifest-Season3Episode2/issues/hd-series-manifest-season-3-episode-2-hd-online-full-episodes-issue-1-545572
https://www.getrevue.co/profile/KeepingUpwiththeKardashians20-04/issues/free-series-keeping-up-with-the-kardashians-season-20-episode-4-hd-online-full-episodes-issue-1-545584
https://www.getrevue.co/profile/Series-Mom-Season8Episode13/issues/free-series-mom-season-8-episode-13-hd-online-full-episodes-issue-1-545591
https://www.getrevue.co/profile/Law-Order-Organized-Crime-S1E2/issues/free-series-law-order-organized-crime-season-1-episode-2-hd-online-full-episodes-issue-1-545600
https://www.getrevue.co/profile/Made-For-Love-Season1Episode4/issues/free-series-made-for-love-season-1-episode-4-hd-online-full-episodes-issue-1-545609
https://www.getrevue.co/profile/Clarice-Season1Episode7/issues/free-series-clarice-season-1-episode-7-hd-online-full-episodes-issue-1-545625
https://www.getrevue.co/profile/Everythings-Gonna-Be-Okay-S2E1/issues/free-series-everything-s-gonna-be-okay-season-2-episode-1-hd-online-full-episodes-issue-1-545635
https://www.getrevue.co/profile/Meet-the-Richardsons-S2-E1/issues/free-series-meet-the-richardsons-season-2-episode-1-hd-online-full-episodes-issue-1-545639
https://www.getrevue.co/profile/Last-Man-Standing-S9-E14/issues/free-series-last-man-standing-season-9-episode-14-hd-online-full-episodes-issue-1-545647
https://steemkr.com/women/@jurigsawah/7-behaviors-women
https://cox.tribe.so/post/jurigsawah-7-behaviors-women-606deb06f301980e88349d1d
https://myanimelist.net/blog.php?eid=848806
https://paiza.io/projects/iGQC67vjjemKm_hOkqtjSw
https://onlinegdb.com/S1b_sPoH_
https://jsfiddle.net/andoloki/ux9sb8f7/
http://divasunlimited.ning.com/profiles/blogs/7-behaviors-women
https://www.peeranswer.com/question/606de93b7e181c6a66d7b684
https://ideone.com/kHP2Ii
https://dumpz.org/azdn2TqQ8YPD
http://paste.jp/bcf686d8/
https://rentry.co/bwq77
https://www.guest-articles.com/art-culture/7-little-things-that-can-tell-you-a-lot-about-someone-07-04-2021
https://www.guest-articles.com/art-culture/7-little-things-that-can-tell-you-a-lot-about-someone1-07-04-2021
https://www.guest-articles.com/art-culture/7-little-things-that-can-tell-you-a-lot-about-someone2-07-04-2021
https://www.guest-articles.com/art-culture/7-little-things-that-can-tell-you-a-lot-about-someone3-07-04-2021
https://www.guest-articles.com/art-culture/7-little-things-that-can-tell-you-a-lot-about-someone4-07-04-2021
https://dreampirates.us/business/7-little-things-that-can-tell-you-a-lot-about-someone6-07-04-2021
 



Category : business

Should I Get A Oracle 1Z0-062 Certification?

Should I Get A Oracle 1Z0-062 Certification?

- You will find numerous leads to why much more and in some cases more dad and mom pick assets schooling as a different to the normal universities


Telemedicine Market - Industry Analysis, size, Share and Upcoming Trends (2021-2027)

Telemedicine Market - Industry Analysis, size, Share and Upcoming Trends (2021-2027)

- As per the research report, Telemedicine Market is anticipated to expand immensely by 2027 at a significant CAGR during the forecast period (2021-2027)


Child Presence Detection System Market Assessment Covering Growth Factors and Upcoming Trends

Child Presence Detection System Market Assessment Covering Growth Factors and Upcoming Trends

- Child Presence Detection System Market stood at US$ 52.36 million in 2018 and is expected to grow at a CAGR of 34.24% during the forecast period 2019-20


Healthcare Fraud Detection Market Industry Analysis and Forecast 2021-2027

Healthcare Fraud Detection Market Industry Analysis and Forecast 2021-2027

- Healthcare Fraud Detection Market - UnivDatos Industry Analysis- by Size, Share, Growth, Trends, and Forecast 2021-2027 | On-Premises, On-Demand