Note: despite the linked duplicate not being a duplicate (it explicitly asks about casting to int and float separately) I still mark it as duplicate because it contains wonderful information about the subject (and an answer similar to my solution) Summary: I am looking for a pythonic way to convert a string into a number (an integer or a float). I currently use a waterfall function but while it works, it is not particularly aesthetically pleasant: def convert_to_int_or_float(a):     # maybe an integer     try:         return int(a)     except ValueError:         # nope - so can be a float or a str         try:             return float(a)         except ValueError:             # must be a str             return a  for s in [&quot;0&quot;, &quot;12&quot;, &quot;-13&quot;, &quot;14.7&quot;, &quot;-14.7&quot;, &quot;hello&quot;]:     print(s, type(convert_to_int_or_float(s)))  # outputs  # 0 &lt;class 'int'&gt; # 12 &lt;class 'int'&gt; # -13 &lt;class 'int'&gt; # 14.7 &lt;class 'float'&gt; # -14.7 &lt;class 'float'&gt; # hello &lt;class 'str'&gt;  Is there a better way to do that? (ideally though a module) I had  look at math but did not find anything there.
In Python, how can I parse a numeric string like "545.2222" to its corresponding float value, 545.2222? Or parse the string "31" to an integer, 31?  I just want to know how to parse a float str to a float, and (separately) an int str to an int.
Difference between "I have got" and "I have gotten" I see these two expressions are used almost identically in different contexts. Is there a difference between I have got and I have gotten? One-sided limits of $f'(x)$ at a point vs. one-sided limits of the difference quotient at that point I know that if a function is piecewise, then when differentiating it one needs to deal separately with the points of intersection of the pieces, because the derivative may not be defined there.  Also, if a one-sided limit of $f'(x)$ at these "crucial points" is infinite or doesn't exist, it doesn't preclude the limit of the difference quotient from existing and being finite. For example, take $f(x)=x^2\sin\frac1x, f(0)=0$: $f'(x)= 2x\sin\frac1x-\sin\frac1x $ has no limit as $x\to0$ but $\lim\limits_{h\to0}\frac{f(h)-f(0)}{h}=0=f'(0)$.  On the contrary, looking at $f(x)=\sin x +\lvert \sin x\rvert $ on $[0,2\pi]$ one has $f'(x)=2\cos x$ on $(0,\pi) $ and $f'(x)=0$ on $(\pi,2\pi)$ so $\lim\limits_{h\to0^+}f'(\pi+h)\ne\lim\limits_{h\to0^-}f'(\pi+h)$, but they are both finite. And in this case it's easy to find that they agree with the one-sided limits of the difference quotient. Why? Does the finiteness of the former imply that they agree with the latter? Is this also true if the one-sided limits of $f'$ at the crucial points agree with each other? Ubuntu does not offers me "install alongside Windows" How can I prove that if $n$ is even then $n^2$ is even and if $n$ is odd then $n^2$ is odd? How to fix sculpting ridges? I ran into a problem I have never seen before and that is when I try to sculpt on a mesh, it sculpts like this:  Instead of this: I am using dyntopo with these settings:   I feel like theres a very obvious solution to this, but I have no idea what it is. How do I get the CPU temperature? How do I get the CPU temperature? Give moderators the option to select a deletion reason when removing posts I have very little background in physics, so I apologize if this question is painfully naive.  Consider the following thought experiment: an observer is in a closed room whose walls, floor, and ceiling are made entirely of mirrors, with a single light source in the middle of the room. When the light is on, the observer can see many copies of his reflection all over the place.  Suddenly, the light source turns itself off. Intuitively, I would expect the observer to "instantly" see darkness. However, I can't figure out why that is the case under the "particle" interpretation of light. There are obviously lots of photons already in the room from before. Furthermore, we know that they don't get "consumed" when they hit a wall, because otherwise the observer wouldn't see so many reflections of himself. Basically, when the light goes off, what happens to the photons already in the room?  I suspect the answer goes something like this: the photons in the room lose a little bit of energy every time they bounce off a mirror, but it's so minuscule that we can still see more reflections than our eye can resolve anyway. When the light goes off, however, it takes them a very small fraction of a second to bounce around the room enough times to diffuse completely, which our eye cannot detect.  Is that about right? If we had a theoretical "perfect reflector", would the light remain trapped in the room forever? If we had instruments that could measure such things very finely, would it take (slightly) longer for the light to go out in a room made of mirrors as opposed to a room made of, say, black cloth? Bring Debian to second Position in the GRUB Menu at startup So, I currently have BOSS Linux and I am going to install Debian (currently installing right now)   And I want my older OS (BOSS linux), on the first position and the debian, (freshly installed) to be on the second. How do I do that? Schrödingers MySQL table: exists, yet it does not Is there any way to run file explorer as administrator under Windows 10 After install Windows 10, it seems that I lost the ability to run explorer.exe as administrator with a user in administrator group.   The reason I want to do that is, in our team's development environment, we are using a C# exe to do some environment configuration which will start command prompt under administrator mode and subst a drive. As a result those substed drives are not visible within the file explorer since it is run not as administrator. That will be kind of inconvenience and sometimes make mistakes.   I was able to run explorer.exe from task manager with the option "create with privileges" checked and then I can see all the drives in explorer. But now this is not working anymore.   I knew there are other options to workaround this workflow, but just want to make sure that if it is now totally impossible under Windows 10?  Any comment is appreciated. I think it would be nice to display tags in alphabetical order. Currently, tags are displayed in order of creation.  As a workaround, I remove, and then add the tags, which is a bit dumb, but I like 'em in alphabetical order.  It's probably pretty trivial to implement, and nice to have! How to create quizzes with macqtex? How to check if a process is running via a batch script Show that the set $\mathbb{Q}[\sqrt{2}] = \{a + b \sqrt{2} \mid a, b \in \mathbb{Q}\}$ is a field with the usual multiplication and addition. Bootstrapped confidence intervals: different values at every computation? I am running an ANOVA and computing bootstrapped CIs for my effect sizes. I am using for this the Measures of Effect Size Toolbox for Matlab.  To my surprise, if I re-run the same line of code, i.e. compute the same thing for the same data, the lower&amp;upper margins of the CI are slightly different each time.  I know that bootstrapped CIs are built from permutation analyses based on random generations of distributions. Still, I do not remeber reading anywhere this odd property of CIs of being never twice the same! How to Delete Elements from List1 appearing in List2? Relation between rank and number of distinct eigenvalues of a matrix Let $T : V\to V$ be a linear transformation such that $\dim\operatorname{Range}(T)=k\leq n$, where $n=\dim V$. Show that $T$ can have at most $k+1$ distinct eigenvalues.   I can realize that the rank  will correspond to the number of non-zero eigenvalues (counted up to multiplicity) and the nullity will correspond to the 0 eigenvalue (counted up to multiplicity), but I cannot design an analytical proof of this.  Thanks for any help . Choose information when copying profile Prove that $f$ analytic, $f(x) \in \mathbb{R}$ for all $x \in \mathbb{R}$ implies $f(\overline{z})=\overline{f(z)}$ Let $U\subset \mathbb{C}$ be a nonempty connected open set such that for every $z\in U$, $\overline z\in U$.  Let $f$ be analytic on $U$. Suppose $f(x)\in\mathbb R$ for every $x\in U\cap\mathbb R$. Prove that $f(\overline{z})=\overline{f(z)}$ for any $z \in U$.    By definition, I know that $f$ analytic on $U$ means that for every $z_0 \in U$, there exists $r&gt;0$ and a sequence of complex numbers $\left(a_n\right)_{n=0}^\infty$ such that $f(z)=\sum_{n=0}^\infty a_n\left(z-z_0\right)^n$ on the disc $D(z_0,r)\subseteq U$. I see that $f$ takes points without imaginary components to other points without imaginary components. But I don't see how this implies a symmetry that $f(\overline{z})=\overline{f(z)}$ for $z \in \mathbb C \setminus \mathbb R$. It seems like a very strong conclusion and I'm not sure how I would prove it.  I have also shown in the preceding question that $U\cap\mathbb R$ contains an open interval, however I am not sure if that detail is meant to be helpful to this question.