Pythonic way to print list items

后端 未结 11 1026
渐次进展
渐次进展 2020-11-22 10:29

I would like to know if there is a better way to print all objects in a Python list than this :

myList = [Person(\"Foo\"), Person(\"Bar\")]
print(\"\\n\".joi         


        
11条回答
  •  遇见更好的自我
    2020-11-22 11:11

    I recently made a password generator and although I'm VERY NEW to python, I whipped this up as a way to display all items in a list (with small edits to fit your needs...

        x = 0
        up = 0
        passwordText = ""
        password = []
        userInput = int(input("Enter how many characters you want your password to be: "))
        print("\n\n\n") # spacing
    
        while x <= (userInput - 1): #loops as many times as the user inputs above
                password.extend([choice(groups.characters)]) #adds random character from groups file that has all lower/uppercase letters and all numbers
                x = x+1 #adds 1 to x w/o using x ++1 as I get many errors w/ that
                passwordText = passwordText + password[up]
                up = up+1 # same as x increase
    
    
        print(passwordText)
    

    Like I said, IM VERY NEW to Python and I'm sure this is way to clunky for a expert, but I'm just here for another example

提交回复
热议问题