You are on page 1of 5

1/30/2021 Python for O&G Lecture 11 - Methods in Strings Part 1 - Colaboratory

Python for Oil and Gas

Website - https://petroleumfromscratchin.wordpress.com/

LinkedIn - https://www.linkedin.com/company/petroleum-from-scratch

YouTube - https://www.youtube.com/channel/UC_lT10npISN5V32HDLAklsw

lenght function

sub = 'Production'

len(sub)

10
/
1/30/2021 Python for O&G Lecture 11 - Methods in Strings Part 1 - Colaboratory

sub_2 = 'Production ,'

len(sub_2)

12

lower method

# Difference between methods and functions

# As of now, you can understand

# Both methods and functions perform functionality for us

# Key Difference: concept of class and it's object

# more on their difference later on after discussion on Functions

# syntax - var_name or string name.method_name()

var = 'PeTRoleUm frOM scRAtch'

var.lower()

'petroleum from scratch'

print(var)

PeTRoleUm frOM scRAtch

/
1/30/2021 Python for O&G Lecture 11 - Methods in Strings Part 1 - Colaboratory

Upper method

var.upper()

'PETROLEUM FROM SCRATCH'

title method

#first letter of each word is capital

var.title()

'Petroleum From Scratch'

count method

# used to count a particular character in a string

var.count('r')

var.count('R')

var.count('m')

# we have already seen the split method


/
1/30/2021 Python for O&G Lecture 11 - Methods in Strings Part 1 - Colaboratory

Assignment 6

# Ask computer for two inputs in a single line. First input be any number in words, second input be same number in numerics
# Both the inputs is to be separated by character ,
#print the length of that word
# print that word in all capital letters using a method
# print the count of any character in this word
# Print the data type of numerical value input by the user and then convert the datatype to a float type

/
1/30/2021 Python for O&G Lecture 11 - Methods in Strings Part 1 - Colaboratory

You might also like