+ 3
question
who can that explain? I dont understand the meaning of „%s in the code txt = "snow world" print("%s" % txt[4:7]) many thanks https://code.sololearn.com/cY1Qqcd6awir/?ref=app
5 Antworten
+ 5
is this *old- fashioned code* really a question in a current challenge?
+ 4
It is the old fashion way of string formatting. %s is a place holder and it is a string. So the print statement says: print a string (referring to %s), and the content (%) is txt[4:7].
Similarly there is a %d which means a number; %f means float, and other which I really can’t remember.
+ 3
yes it was a question from today
+ 2
I found some challenges introduce functions which are not covered in the courses, or at least I haven't seen them in the courses. For example: iter().
Maybe they were discussed in the older courses which are "retired"?
Usually I go over the questions after challenge, and look for what I was wrong or don't understand, and then fire up Python IDLE to make test or search on web for more info.
+ 2
Angela
Google for "Python c-style print formatting".
If you come from a c programming background, you might be familiar with it from printf().
The new way is to use f-strings.
But if you are learning from older reference materials, understaning how to use this syntax is useful.
here is a good site:
https://www.learnpython.org/en/String_Formatting