Function calls are a fundamental part of programming in
Python. However, a simple oversight like forgetting to include
parentheses can have significant repercussions. In this
article, we’ll explore the potential pitfalls of forgetting
parentheses in function calls and highlight the importance of
this seemingly small detail.
In Python, tuples are an ordered and immutable collection of
elements. They are often used to store related pieces of
information together, such as the x and y coordinates of a
point or the name and age of a person. Sometimes, we may need
to find the position of a particular element within a tuple.
Python provides a built-in method called
index() that makes it easy
to accomplish this task. In this article, we will explore how
to use the index() method
to get the index of an element in a tuple.
The index() method is a
built-in method in Python that returns the index of the first
occurrence of a specified element in a tuple. The method takes
a single argument, which is the element to search for. Here’s
an example:
In this example, we created a tuple called
my_tuple that contains six
elements. We then called the
index() method on the
tuple, passing in the string
'f' as the argument. The
method returns the index of the first occurrence of
'f' in the tuple, which is
2. We printed the result to the console using the
print() function.
If the specified element is not present in the tuple, the
index() method raises a
ValueError exception. For
example:
my_tuple = ('a', 1, 'f', 'a', 5, 'a')
print(my_tuple.index('z')) # ValueError: tuple.index(x): x not in tuple
In this example, we called the
index() method on the
my_tuple tuple, passing in
the string 'z' as the
argument. Since 'z' is not
present in the tuple, the method raises a
ValueError exception.
When working with conditional statements in Python, it’s
important to understand what values evaluate to
True and what values
evaluate to False. While
some values are obviously
True, such as any non-zero
number or a non-empty string, there are a few other values
that can sometimes trip up programmers. In particular, the
values None,
"False", and the
number 0 are all examples
of values that evaluate to
False in Python.
When we hear the name of people who amaze us with their
accomplishments, we tend to forget how much they had to go
through to get there. This also includes rejections and
multiple failures.
For example, you may have already heard about Elon Musk, but
you may have not heard that he actually couldn’t get a job at
Nestcape.
Sometimes you may get an input that is a string, but you
actually need it to be a list, or a list of lists.
There are many alternatives that you can use to convert such
strings into lists, or list of lists, but in this article, I
am going to mention here a really quick way.
YouTube is a really great place if you want to learn new
things, and also publish your own videos. You can use it as an
online library in which you put your own videos too, without
having to lose hundreds of gigabytes of your memory.
JSON is a very popular file format. Sometimes we may have a
JSON object inside a browser tab that we need to read and it
can be difficult. We may need to go and search for an online
tool that turns it into an easy-to-read format, so that we can
understand it. Now here is a Chrome and Firefox extension that
does the formatting and makes your JSONs instantly pretty
inside your browser, without having to go and do many
unnecessary steps.
If you have a Rails project and want to export a table as a
CSV, without having to go through all the steps of finding a
gem, installing and using it and then uninstall it, as it is
no longer needed, then I have some good news. Here is a quick
way to export a particular table from your database as a CSV
file very easily and quickly.
I recently changed my laptop and while I was trying to
create a new React Native application in my new development
environment, the process of creating the app seemed to hang
on forever. It did not finish at all, and took a lot of my
time, as I was hoping that it will ultimately finish. I was
worried about this and this way, I tried to find solutions
online in as many places as I could. It took a lot of test
and error cases, and a lot of browsing until I finally
stumbled upon a solution that will hopefully be beneficial
to you as well.
The last message that showed up on the terminal when I was
trying to create a new React Native was: “Building fresh
packages react native”.
What I had to do was run the following command in the
terminal:
yarn add uws
Then I was able to create new React Native application
using the React Native command line interface within
seconds.
There may be other solutions to this problem, and this is
the one that worked for me. If you are having the same
issue, then chances are this solution can hopefully work for
you as well.
In a recent email, the author of the book The Best Place to
Work: The Art and Science of Creating an Extraordinary
Workplace, Rod Friedman mentioned something very interesting.
He told a story that happened to him and his daughter
recently. A couple of days ago he went to the cinema with his
daughter and although they had an unpleasant experience while
watching the movie, they did not recall that particular story
that way. They initially did not like the movie and considered
it as not worth their time, but later on, as they were
thinking a bit differently. They actually did change their
opinion about the movie and thought that it was not that bad,
and that it did deserve worth a watch. Rod considered this
occurrence to happen as a result of our different selves that
might change throughout different times.
Continue reading