Note the following.
class Animal:
def __init__(self):
pass
a = Animal()
b = Animal()
print(type(a)) # <class 'Animal'>
print(type(b)) # <class 'Animal'>
print(type(35)) # <class 'int'>
print(type("hello")) # <class 'str'>
print(type([1,3,5]) # <class 'list'>
Note that all integers such as (35, 1, 2, 3, etc) are all just objects/instances of a class "int". All strings such as "hello", "a", "abc", are all just objects/instances of class "str".
For this particular challenge, let's have you look into some of the default functions available within class "str". Please google "Python string methods", and you'll see bunch of methods available within class string. Get familiar with the following methods:
- Updating Letters
- capitalize()
- lower()
- upper()
- Validations
- isalnum()
- isnumeric()
- String Manipulations
- join()
- split()
- strip()
- replace()
Challenges
Once you get familiar with these methods, please work on the following challenges.
- Write a function 'threeVersions' that takes a given string and returns a dictionary with three values. First value is the lower case version of the string, the second value the upper case version of the string, and the last value where it's capitalized. For example, for threeVersions("haCKer heRO") should return { "lower": "hacker hero", "upper": "HACKER HERO", "capital": "Hacker hero" }
- Write a function 'simpleValidations' that takes a string and determines whether it's alphanumeric or isnumeric. If it's alphanumeric, have the function return 1. If it's numeric, have it return 2. If it's neither, have the funciton return 0. For example, simpleValidations("123ABc") should return 1; simpleValidations("123") should return 2; simpleValidations("123!$") should return 0.
- Write a function 'analyzeString' that takes a string and returns a dictionary containing information about how many characters exist in that string. For example, analyzeString("hackerhero") should return { "h": 2, "a":1 ,"c"1: ,"k"1: ,"e":2 ,"r":2 , "o":1 }. Show how many characters (in lower characters) exist. For example analyzeString("HAckERHero") should still return the same output.