2019-06-05 22:09:51 (edited by Turkce_Rap 2019-06-05 22:10:51)

Hi guys, i didn'T understand why the code contains {:<10} is it something like limitting parametres?

def reg(**args):
    print("-"*30)

    for key, value in args.items():
        print("{:<10}: {}".format(value, key))

    print("-"*30)

reg(name="Someone", surname="asdf", city="İstanbul", phone="00000000")

Thumbs up

2019-06-05 22:25:51 (edited by Ethin 2019-06-05 22:26:16)

I find it difficult to figure out what your trying to do. In either case, the items within the braces are format specifiers. Note that, if there was an f just before the opening quotation mark in the formatted string, that would create an f-string, which would make it search for a variable with that name.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

2019-06-05 22:41:39

Ethin wrote:

I find it difficult to figure out what your trying to do. In either case, the items within the braces are format specifiers. Note that, if there was an f just before the opening quotation mark in the formatted string, that would create an f-string, which would make it search for a variable with that name.




i don't  get what your point was  though, those strings are in dict format.

those are just nameless parametres that would register users with other infos such as name, city, phone. etc.

Thumbs up

2019-06-05 23:19:30

@3, my point is this.
This:
print("This is a {}".format("test"))
Will print
This is a test
Because the {} signify a formatter specifier. I.e.: {:,} will format numbers with comma separators.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

2019-06-05 23:28:22

Ethin wrote:

@3, my point is this.
This:
print("This is a {}".format("test"))
Will print
This is a test
Because the {} signify a formatter specifier. I.e.: {:,} will format numbers with comma separators.


Ok, so what is that <10 above?

Thumbs up

2019-06-06 00:16:50 (edited by Ethin 2019-06-06 00:17:42)

@5, that is what I've been trying to tell you all along -- a format specifier. I'm not sure what it does, but considering that it has .format() after it, its formatting a string with those characters within the braces.

"On two occasions I have been asked [by members of Parliament!]: 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out ?' I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question."    — Charles Babbage.

Thumbs up

2019-06-06 00:48:18 (edited by thggamer 2019-06-06 00:56:46)

The <10 part completes the text adding spaces to the right while it doesn't reach 10 characters.
So if you have a string ("abcd" for example) it will become "abcd      " because abcd has 4 characters and 6 are left to complete the 10 remaining characters specified in the format.
Edit: you can have the same effect by using the ljust function:
"abcd".ljust(10) will return "abcd      "

Thumbs up

2019-06-06 13:11:52

Guys Thank you boath, now i knew

Thumbs up