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

Thursday, July 21, 2022

[FIXED] How to convert a single char in a sliced String into Integer in Python?

 July 21, 2022     casting, char, integer, python, string     No comments   

Issue

For example, I have a


String = "TGR1UK"

I only need the number 1 in the string to do some math operation so I make a number variable as


number = String[3]

but the type of this "number" is actually Char and I cant use

number = (int)String[3] 

to cast it into an integer

what should I do?


Solution

number = int(String[3])

This will cast it to an int. Read more here:

https://careerkarma.com/blog/python-string-to-int/

Edit: I have assumed when you said:

but the type of this "number" is actually Char and I cant use number = (int)String[3]

That you meant that wasnt working, because that is not how you cast to an int in python. Did you mean you aren't allowed to use a straight cast for some reason?



Answered By - Aaron56
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

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