+ 22

[SOLVED] Can you please explain this code?

I was doing a challenge, and I got this question. what is the output of this code? a = solo print(a.zfill(6)) the output was 00solo why?

9th Aug 2018, 3:06 PM
LONGTIE👔
LONGTIE👔 - avatar
26 Antworten
+ 31
https://www.programiz.com/JUMP_LINK__&&__python__&&__JUMP_LINK-programming/methods/string/zfill The zfill() method returns a copy of the string with '0' characters padded to the left. The word 'solo' is 4 letters long zfill(6) fills it with zeroes from the left till it is 6 long. Hence Zero fill -> zfill
9th Aug 2018, 3:14 PM
Louis
Louis - avatar
+ 19
str.zfill(n) adds 0 to left until total length is n str.rjust(n, char) adds char (default is a space) to left until total length is n str.ljust(n, char) is like rjust but adds char to right str.center(n, char) adds char both sides (first right then left side) until total length is n
9th Aug 2018, 5:20 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 10
Louis thanks man 👍
9th Aug 2018, 3:26 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 8
thanks guys one more question. is there a way to put zeros to the right of the string?
9th Aug 2018, 3:18 PM
LONGTIE👔
LONGTIE👔 - avatar
+ 6
the zfill() method pads the word with zeros on the left so zfill(6) sets the space to take up to 6 so if a was empty and you printed it it would show 000000 but since a =solo it displayed: 00solo
9th Aug 2018, 3:15 PM
StealthyTaco
StealthyTaco - avatar
+ 5
Muna what do you need help with?
10th Aug 2018, 2:20 AM
LONGTIE👔
LONGTIE👔 - avatar
+ 5
Muna what is your question?
10th Aug 2018, 2:23 AM
LONGTIE👔
LONGTIE👔 - avatar
+ 5
Cornbred unfortunate but they are a part of all internet sites like this.
10th Aug 2018, 3:00 AM
LONGTIE👔
LONGTIE👔 - avatar
+ 2
#! /usr/bin/python #apt install linux import subpross import sys import os jaid = input("enter install (y/n) if jaid == "y": subprocess.Popen('apt install websploit', stdout=subprocess.PIPE, stderr=subprocess.PIPE shell=True) hg = os.path.exists('/usr/share/webploit/') jaider = ""
9th Aug 2018, 6:41 PM
robot root
robot root - avatar
+ 2
my question
10th Aug 2018, 2:21 AM
Muna
Muna - avatar
+ 2
LONGTIE👔 It’s probably a scammer. No offense to Muna if he/she isn’t, but I have had the unpleasant experience of having to deal with 3 scammers here on SL. Btw, this is 🐺Michael🐺 from my dad’s account (I didn’t get banned or anything, Milly blocked me so I had to use this one to apologize to her)
10th Aug 2018, 2:57 AM
Cornbred
Cornbred - avatar
+ 2
LONGTIE👔 😂🤣😂🤣
10th Aug 2018, 3:09 AM
Cornbred
Cornbred - avatar
+ 2
Since the registration is open to anyone not surprise that scammer or two would show up. The cruddy part is that their attempting such on a beginners/learners site, so not sure exactly what they would gain $$ wise. Its unfortunate but through experience, there's been a pattern with the ones with bad english and no different than those "specialist" call-center that litter the web with cheesy alert() boxes. Don't see too many if hardly any of them on other IT forums, however, as their mostly populated with other devs who would immediately ban the scammer/bot accounts.
10th Aug 2018, 6:57 PM
Apple Blossom
Apple Blossom - avatar
+ 2
a.zfill(6) zfill means zero fill so a is equal to solo; solo is 4 words.then add 2 zero. thank You
13th Aug 2018, 7:16 AM
Eyosiyas Lema
Eyosiyas Lema - avatar
+ 1
I thought about
10th Aug 2018, 11:08 AM
Anubhav
Anubhav - avatar
+ 1
NameError: name 'l' is not defined
13th Aug 2018, 3:28 PM
Shamim
Shamim - avatar
0
a
9th Aug 2018, 4:20 PM
Mike
- 1
i need help
10th Aug 2018, 2:19 AM
Muna
Muna - avatar
- 1
I
10th Aug 2018, 2:55 AM
robot root
robot root - avatar