Lecture 2 - Python Functions and Working with Files

One way to do this is to create a new list and add only the elements you select.

Example:

fruit = ['apple', 'pineapple', 'strawberry', 'banana']

red_fruit = [] # create an empty list
red_fruit.append(fruit[0]) # append the 1st element of the list 'fruit' to the list 'red_fruit'
red_fruit.append(fruit[2])
2 Likes

f"Hello I am an { stream}" is correct syntax… for f strings…

probably because they were introduced recently, they work so much better, but it is not the most common format in already working environments.

6 posts were split to a new topic: Difference between try/except and if/else?

hi , few notebooks i have completed last week for lesson 1 . are the notebooks same ?
do we have to work on it again and commit again?

6 posts were split to a new topic: Difference between .ceil() and .round()?

You can use escape characters \ to print the marks

stream = “engineer”
print(f"Hello I am an “{ stream}” . Thank you!")

Don’t know if it helps

1 Like

You can use escape characters \ to print with the marks

stream = “engineer”
print(f"Hello I am an \“{ stream}\” . Thank you!")

Don’t know if it helps

A Functionfunction is a piece of code that is called by name. It can be passed data to operate on (i.e. the parameters) and can optionally return data (the return value). All data that is passed to a function is explicitly passed.

A Method is a piece of code that is called by a name that is associated with an object. In most respects it is identical to a function except for two key differences:

1. A method is implicitly passed the object on which it was called.
2. A method is able to operate on data that is contained within the class (remembering that an object is an instance of a class - the class is the definition, the object is an instance of that data).

2 Likes

3 posts were split to a new topic: How to create new module in Python?

that is a very cool project Aakash! :open_mouth: thank you!

:clap: :clap: Thanks for the great lecture @aakashns and team members! It was very resourceful and useful!

3 Likes

@aakashns can you please comment whether the mentoring will benefit people, who seek to be independent service providers in the future?

2 Likes

Again, it was a great lecture. Thank you @aakashns and the team.

Got it! It just takes the data type of the variable we gonna use in the format method.
I was just trying to get the entire argument’s type as below:

>>> age = 25
>>> me = "my name is {} and I'm {} years old".format(name,age)
>>> me
"my name is candy and I'm 25 years old"
>>> type(me)
<class 'str'>
>>> type(format(name,age))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: format() argument 2 must be str, not int

Trying some crazy stuff just like the last couple of lines in the code segment. :stuck_out_tongue:

Thank you @alexander-hecke :smiley:

1 Like

will be nice to have the link to gain more info about it!

3 posts were split to a new topic: Difference between multi-line comments and docstring?

Thanks for the lectures @aakashns, it was very educative, i learnt a lot.

1 Like

Shaik, you can press ENTER key after pasting the API key to continue. (You may have already found the answer by now…)

I had the same question to myself after I pasted the API key and didn’t see any action after that. I pressed key to execute it again and that worked, but then I simply pressed ENTER key on another notebook and that worked too.

Hello all,
I just finished up the first assignment. Is there a second assignment for this week or do we have a free week since the course was extended?
thanks
entropyeve