python - Split User input into different Variables -


i'd take user input (like ip address) , split parts separate variables

for example

255.255.255.0

now, split string decimal points , save each part own variable. 255 variable1, 2nd 255 variable2, 3rd 255 variable3 , 0 variable 4 integers.

how can this?

you do:

a, b, c, d = input().split(".") 

the split() method, default, splits string @ each space list. but, if add optional argument, split string character/string. can read more @ official documentation

you can check make sure input in proper ipv4 format.

if re.match("\d+[.]\d+[.]\d+[.]\d+", input()):     print("ipv4 format") 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -