PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, July 20, 2022

[FIXED] How to split a string into a string and an integer?

 July 20, 2022     integer, python, split, string     No comments   

Issue

How do you split a string into a several strings in python. The string I am trying to split is in the format of:

Variable 1

and I would like to split it into:

Variable = Variable

Number = 1


Solution

You could split based on the space in the example you gave, unless you need a more generic approach.


# set up your variable
my_var = "variable 1"

# You can split by the space in this instance, if all of your data will look the same
my_split = my_var.split(" ")

# prints variable
print(my_split[0])

# prints 1
print(my_split[1])



Answered By - syntheticgio
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing