• Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Have any question?

(+91) 98222 16647
info@simplycoding.in
RegisterLogin
Simply Coding
  • Home
  • Courses
  • School
  • Programs
  • Problems
  • Contact Us
  • My account
  • Register

Python

Python Problems on Strings

  • Categories Python, Python Tokens

Python Problems on Strings:

1)Write a program to find the length of the string “refrigerator” without using len function.
Ans.
a = "refrigerator" 
count = 0
for i in a:
  count = count+1
print (count)  
>>>    12    
 
2)Which of the following is not a Python legal string operation?
  1.    ‘abc’+’abc’ 
  2.    ‘abc’ * 3 
  3.     ‘abc’ + 3 
  4.    ‘abc’.lower( )  
Ans.  ‘abc’ + 3 is not legal string operation  
 
3)What would the following expression return? 
  1.     “Hello World”.lower().upper() 
  2.     “123FGH”.isdigit() 
  3.     ‘Hello World’.find(“Wor”) 
  4.    ‘Hello World’.isalpha()
Ans.
  1.                 HELLO WORLD
  2.                 False
  3.                  6
  4.                 False  
 
4)What will be the output produced by the following code fragments?
y=str(123)
x="hello"*3
print(x,y)
Ans. hellohellohello 123  
 
5)What will be the output produced by the following code fragments?
x="hello"+"world"
y=len(x)
print(y,x) 
Ans. 10 helloworld    
 
6)What will be the output produced by the following code fragments?     
x="hello"+"to python"+"world"
for char in x:
    y=char
    print(y,':',end='')
Ans. h:e:l:lo: :t:o: :p:y:t:h:o:n: :w:o:r:l:d:
 
7)What will be the output produced by the following code fragments?          
x="hello world"
print (x[2:-3],x[-4:-2]) 
Ans.  llo wo or  
 
8)What will be the output ?
print('fun'+'trial'+'ooty'*3) 
Ans.  funtrialootyootyooty    
 
9)Write the expression to reverse the string using slicing method?  
Ans.
str="hello world"
print (str[::-1])
>>>   dlrow olleh  
 
10)  What will be the output ?
st="Hello World"
print (st.replace(st[6],"#")) 
Ans. Hello #orld  
 
11)  What will be the output?
x="hello world"
print (x[:2],x[:-2],x[-2:])
Ans.  he hello wor ld

  • Share:
author avatar
Simply Coding

Previous post

CBSE Python Questions on Operators
April 24, 2020

Next post

Crack CBSE Python Questions on Tokens
April 24, 2020

You may also like

Tokens1
Python Tokens
15 June, 2021
Random Module
Practice short problems on Python Random Module
25 April, 2020
Python Questions on Tokens
Crack CBSE Python Questions on Tokens
24 April, 2020

Leave A Reply Cancel reply

You must be logged in to post a comment.

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String

Categories

  • Uncategorized
  • Programs
    • Python
    • Java
  • Problems
    • Python
    • Java
    • Web Development
      • Internet
    • Emerging Technologies
  • Notes
    • General
    • QBasic
    • MS Access
    • Web Development
      • XML
      • HTML
      • JavaScript
      • Internet
    • Database
    • Logo Programming
    • Scratch
    • Emerging Trends
      • Artificial Intelligence
      • Internet of Things
      • Cloud Computing
      • Machine Learning
    • Computer Fundamentals
      • Computer Networks
      • E-Services
      • Computer Hardware
    • Python
    • Java
  • School
    • ICSE
      • Computers Class 9
        • Java Introduction
        • Tokens & Data Types
        • Java Operators
        • Math Library
        • if & switch
        • For & While
        • Nested loops
      • Computer Class 10
        • Sample Papers
        • OOPS concepts
        • Functions in Java
        • Constructors
        • Arrays in Java
        • Strings in Java
    • SSC
      • IT Class 11
        • IT Basics
        • DBMS
        • Web Designing
        • Cyber Laws
      • IT Class 12
        • Web Designing
        • SEO
        • Advanced JavaScript
        • Emerging Tech
        • Server Side Scripting
        • E-Com & E-Gov
      • Computer Science 11
      • Computer Science 12
    • CBSE
      • Computer 9
        • Basics of IT
        • Cyber Safety
        • Scratch
        • Python
      • Computer 10
        • Sample Papers
        • Networking
        • HTML
        • Cyber Ethics
        • Scratch
        • Python
      • Computer Science 11
        • Computer Systems
        • Python 11
          • Python Basics
          • Python Tokens
          • Python Operators
          • Python if-else
          • Python loops
          • Python Strings
          • Python List
          • Python Tuple
          • Python Dictionary
          • Python Modules
        • Data Management
      • Computer Science 12
        • Sample Papers
        • Python 12
          • Python Functions
          • Python File Handling
          • Python Libraries
          • Python Recursion
          • Data Structures
        • Computer Networks
        • Data Management
    • ISC
      • Computer Science 11
        • Introduction to Java
        • Values & Data Types
        • Operators
        • if & switch
        • Iterative Statements
        • Functions
        • Arrays
        • String
        • Data Structures
        • Cyber Ethics
      • Computer Science 12
        • Sample Papers
        • Boolean Algebra
        • OOPS
        • Wrapper Classes
        • Functions
        • Arrays
        • String
Simply Coding Computer Courses for School                Privacy Policy     Terms of Use     Contact Us

© 2021 Simply Coding

Login with your site account

Lost your password?

Not a member yet? Register now

Register a new account

Are you a member? Login now