Python Forum
How can I get values inside of function?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I get values inside of function?
#1
I wrote these codes but there is a problem.

userid=(" ")
userpw=(" ")

def register():
a=input("Username: ")
b=input("Password: ")

How can I get these values from the function instead of userid and pw.
Reply
#2
def register():
    a=input("Username: ")
    b=input("Password: ")
    return a,b

userid, userpw = register()
Recommended Tutorials:
Reply
#3
userid=""
userpw=""

def register():
    userid=input("Username: ")
    userpw=input("Password: ")
    print("%s%s%s%s" %("Username = ", userid, "\nPassword = ", userpw))

register()
or use getpass

import getpass 
  
try: 
    user = getpass.getuser()
    p = getpass.getpass() 
except Exception as error: 
    print('ERROR', error) 
else: 
    print('User:', user, 'Password entered:', p) 
Reply
#4
(Dec-31-2018, 02:21 PM)metulburr Wrote:
def register():
    a=input("Username: ")
    b=input("Password: ")
    return a,b

userid, userpw = register()

When I start the program, always does same thing. I can't move to the next step.
Reply
#5
def register():
    a=input("Username: ")
    b=input("Password: ")
    return a,b

c = register()
userid = c[0]
userpw = c[1]
print ("userid:", userid, "userpw:", userpw)

You should not use input for a password (it is visible then)

better use getpass
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  with open context inside of a recursive function billykid999 1 549 May-23-2023, 02:37 AM
Last Post: deanhystad
  How do I call sys.argv list inside a function, from the CLI? billykid999 3 752 May-02-2023, 08:40 AM
Last Post: Gribouillis
  Adding values with reduce() function from the list of tuples kinimod 10 2,512 Jan-24-2023, 08:22 AM
Last Post: perfringo
  function accepts infinite parameters and returns a graph with those values edencthompson 0 812 Jun-10-2022, 03:42 PM
Last Post: edencthompson
  Need to parse a list of boolean columns inside a list and return true values Python84 4 2,036 Jan-09-2022, 02:39 AM
Last Post: Python84
  Function - Return multiple values tester_V 10 4,316 Jun-02-2021, 05:34 AM
Last Post: tester_V
  How to make global list inside function CHANKC 6 2,978 Nov-26-2020, 08:05 AM
Last Post: CHANKC
  Parameters aren't seen inside function Sancho_Pansa 8 2,814 Oct-27-2020, 07:52 AM
Last Post: Sancho_Pansa
  Function parameters and values as string infobound 1 1,728 Jul-24-2020, 04:28 AM
Last Post: scidam
  Function to return list of all the INDEX values of a defined ndarray? pjfarley3 2 1,916 Jul-10-2020, 04:51 AM
Last Post: pjfarley3

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020