Question

Objective Learn about String methods Work with the Python documentation Specifics Perform a simple Google search...

Objective

Learn about String methods
Work with the Python documentation

Specifics

Perform a simple Google search (or use any other search engine) on “Python String methods”. One of the first links will be to the Python webpage detailing the built-in data types. This page contains a description of the methods available in String variables. You may use other webpages for this assignment, but you need to be aware of the official documentation for the language.

The webpage lists methods that are part of every String variable. The methods can return information about the data in the String variable, such as an integer or a Boolean value, or even return a new String value. NONE of the method will alter the value in the variable.

Given a String variable x identify the method, or methods, which can be used to perform the following tasks. Quite often there are two, and possibly more, methods that could be used perform the tasks. Write the function or method, with the argument(s) (if needed) to perform the tasks. Don’t worry about using the results, just demonstrate how to use the function/method. For example, if the question was “Determine if x starts with a ‘q’”, the method call would be:
x.startswith(‘q’)

  1. Determine how many characters are in x.

  2. Determine the position of the first occurrence of the letter “q” in x.

  3. Determine if the last character in x is the letter “q”.

  4. Get a copy of x in all upper case letters.

  5. Is x already comprised of all upper case letters.

  6. Get a copy of x in all lower case letters.

  7. Determine if x contains any characters at all.

  8. Get a copy of x with the first blank space (" ")changed to a dash ("-").

  9. Get a copy of x with all blank spaces (" ") changed to dashes ("-").

  10. Break up x into one or more values by a delimiter. For example, if a string

    contained “a,b,c”, how could your program return the values “a” and “b” and “c”?

  11. Determine if x “looks like” a number. Remember, the int() function crashes if

    the supplied string doesn’t “look like” a number.

  12. Determine if x “looks like” a name, meaning it contains only the characters ‘a’

    through ‘z’, either upper or lower case.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Thanks for the question, here are all the functions you will be needing.

==========================================================================


x = 'some string'
# Determine how many characters are in x.
characters = len(x)
print(characters)

# Determine the position of the first occurrence of the letter “q” in x.
pos = x.find('q')
print(pos)

# Determine if the last character in x is the letter “q”.
last_character_q = x.rfind('q') == x[-1]

#Get a copy of x in all upper case letters.
upper_case_x = x.upper()

#Is x already comprised of all upper case letters.
is_x_in_upper = x.isupper()

#Get a copy of x in all lower case letters.
x_lower = x.lower()


#Determine if x contains any characters at all.
is_zero_length = len(x)==0

#Get a copy of x with the first blank space (" ")changed to a dash ("-").
x_updated = x.replace(' ','-',1)

#Get a copy of x with all blank spaces (" ") changed to dashes ("-").
x_updated =x.replace(' ','-')

# Break up x into one or more values by a delimiter. For example, if a string
x_splitted = x.split()


#Determine if x “looks like” a number.
is_x_number = x.isnumeric()

#Determine if x “looks like” a name,
is_x_name = x.isalpha()

==========================================================================
Add a comment
Know the answer?
Add Answer to:
Objective Learn about String methods Work with the Python documentation Specifics Perform a simple Google search...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a class StringsAndThings. The class has one instance variable of type String and a constructor...

    Write a class StringsAndThings. The class has one instance variable of type String and a constructor with a parameter to initialize the instance variable. The parameter could contain any characters, including letters, digits, spaces, special characters (+, -, $, @,...), and punctuation marks. Write methods: countNonLetters - that will count how many of the characters in the string are not letters. You can use Character's isLetter method. moreVowels - which returns true if the String parameter has more vowels than...

  • l T-Mobile 1:57 AM Khapt-ridaprodkscoudgate.net inst-fs-iad-prod.inscloudgate.net print if number is evil or not 2. Create two...

    l T-Mobile 1:57 AM Khapt-ridaprodkscoudgate.net inst-fs-iad-prod.inscloudgate.net print if number is evil or not 2. Create two files names shift1.py and shift2.py. Shift1.py will take a word and move the first three characters to the end of the word and change the new first letter to upper case. Shift2.py will take a word and move the last three characters to the start of the word and change the new first letter to upper case Run code and capture results. Upload results...

  • In PYTHON ONLY PLEASE You will use a dictionary in Python You only have string in Python so you have to use a string dat...

    In PYTHON ONLY PLEASE You will use a dictionary in Python You only have string in Python so you have to use a string data type Use a Switch statement.A switch statement is just another way of writing an IF statement. The user will enter f, s, j, or r from the keyboard for freshman, sophomore, junior, or senior. Use character data type for c++. Then you can say something like: char level ='f'; level=toupper(level); You would need a loop...

  • Hi I really need help with the methods for this lab for a computer science class....

    Hi I really need help with the methods for this lab for a computer science class. Thanks Main (WordTester - the application) is complete and only requires uncommenting to test the Word and Words classes as they are completed. The needed imports, class headings, method headings, and block comments are provided for the remaining classes. Javadocs are also provided for the Word and Words classes. Word The Word class represents a single word. It is immutable. You have been provided...

  • JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using...

    JAVA Recursion: For this assignment, you will be working with various methods to manipulate strings using recursion. The method signatures are included in the starter code below, with a more detailed explanation of what function the method should perform. You will be writing the following methods: stringClean() palindromeChecker() reverseString() totalWord() permutation() You will be using tools in the String class like .substring(), .charAt(), and .length() in all of these methods, so be careful with indices. If you get stuck, think...

  • Methods: Net beans IDE Java two methods. Identifier: calculateScore(String word) Parameters: word – the word for...

    Methods: Net beans IDE Java two methods. Identifier: calculateScore(String word) Parameters: word – the word for which you should calculate the points in Scrabble Return Value: int – the number of points for the parameter word Other: This method should be static. This method should use the following system for scoring: 0 – blank 1 – e, a, i, o, n, r, t, l, s, u 2 – d, g 3 – b, c, m, p 4 – f, h,...

  • WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you...

    WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include: a function called encode that takes two parameters: key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; plaintext, a string of unspecified length that represents the message to be encoded. encode will return a string representing the ciphertext. a...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or...

    language is java Restrictions: You are not allowed to use anything from the String, StringBuilder, or Wrapper classes. In general, you may not use anything from any other Java classes, unless otherwise specified. You are not allowed to use String literals in your code ("this is a string literal"). You are not allowed to use String objects in your code. The methods must be implemented by manipulating the data field array, The CSString Class: NOTE: Pay very careful attention to...

  • Programming Assignment #7 (Recursion) This assignment is to write some methods that perform simple array operations...

    Programming Assignment #7 (Recursion) This assignment is to write some methods that perform simple array operations recursively. Specifically, you will write the bodies for the recursive methods of the ArrayRecursion class, available on the class web page. No credit will be given if any changes are made to ArrayRecursion.java, other than completing the method bodies Note that the public methods of ArrayRecursion – contains(), getIndexOfSmallest(), and sort() – cannot be recursive because they have no parameters. Each of these methods...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT