+ 2

Can anyone explain

Print ("%-ns"%S)

6th May 2020, 10:29 AM
《A$# ☆ $ING#》
《A$# ☆ $ING#》 - avatar
5 ответов
+ 2
This is printf-style string formatting. Each format specifier from the string before % operator will be replaced with values which go after % operator. Your format srting has only 1 format specifier %-ns. '%' is the format specifier symbol '-' defines left justification 'n' is the minimum field width. (it should be a number or *) 's' says that value should be printed as string. for example, the output of the code S='55' print('%-4s!!!'%S) will be 55 !!! where %-4s was replaced with 55 inside the field with width 4 and left justified. '!!!' are not format specifiers, they are printed as is.
6th May 2020, 12:49 PM
andriy kan
andriy kan - avatar
+ 1
Space do not affect
6th May 2020, 10:37 AM
《A$# ☆ $ING#》
《A$# ☆ $ING#》 - avatar
0
This code is a total mess. It should be "print" not "Print" There should be no space between t and (.
6th May 2020, 10:34 AM
M Tamim
M Tamim - avatar
0
Yash Raj Singh Sometimes it does. I saw some interpreters (low quality though) throwing errors for extra spaces after print
6th May 2020, 10:44 AM
M Tamim
M Tamim - avatar
0
The 'n' in the format is unrecognised, and variable <S> is undefined. As it is now, the statement is non executable.
6th May 2020, 11:29 AM
Ipang