<jupyter_start><jupyter_text>Setup First, let's make sure this notebook works well in both python 2 and 3, import a few common modules, ensure MatplotLib plots figures inline and prepare a function to save the figures:<jupyter_code># To support both python 2 and python 3
from __future__ import division, print_function, unicode_literals

# Common imports
import numpy as np
import os

# to make this notebook's output stable across runs
def reset_graph(seed=42):
    tf.reset_default_graph()
    tf.set_random_seed(seed)
    np.random.seed(seed)<jupyter_output><empty_output><jupyter_text>Basics of Python<jupyter_code>astring = "Hello world!"
astring2 = 'Hello world!'

astring3 = "Hi' there"
astring = "Hello world!"
print("single quotes are ' '")

print(len(astring))
print(len(" Happy New year "))
astring = "Hello world!"
print(astring.index("H"))
astring = "Hello world!"
print(astring.index("wor"))
astring = "Hello world!"
print(astring.count("w"))
print(astring.count("Hello "))
astring = "Hello world!"
print(astring[3:7])

print(astring[3:20])

print(astring[2])
print(astring[20])
#how to skip characters

astring = "HelloXworld!"
print(astring[3:7])
print(astring[3:7:2])
print(len(astring[3:7:2]))
astring = "Hello world!"
print(astring[3:7:5])
astring = "Hello world!"
print(astring[3:7])
print(astring[3:7:1])
#reverse a string

astring = "Hello world!"
print(astring[::-1])
astring = "Hello world!"
print(astring.upper())
print(astring.lower())
astring = "Hello world!"
print(astring.startswith("Hello"))
print(astring.endswith("asdfasdfasdf"))
#print(astring.endswith("world!"))

print(astring.startswith("Hello world!"))
print(astring.endswith("Hello world!"))
astring = "Hello world!"
afewwords = astring.split("l")
print(afewwords)
#Exercise
#Try to fix the code to print out the correct information by changing the string.

s = "Strings are awesome"
# Length should be 20
print("Length of s = %d" % len(s))

# First occurrence of "a" should be at index 8
print("The first occurrence of the letter a = %d" % s.index("a"))

# Number of a's should be 2
print("a occurs %d times" % s.count("a"))
#Exercise
#Try to fix the code to print out the correct information by changing the string.

# Slicing the string into bits
print("The first five characters are '%s'" % s[:5]) # Start to 5
print("The next five characters are '%s'" % s[5:10]) # 5 to 10
print("The thirteenth character is '%s'" % s[12]) # Just number 12
print("The characters with odd index are '%s'" %s[1::2]) #(0-based indexing)
print("The last five characters are '%s'" % s[-5:]) # 5th-from-last to end
#Exercise
#Try to fix the code to print out the correct information by changing the string.

# Convert everything to uppercase
print("String in uppercase: %s" % s.upper())

# Convert everything to lowercase
print("String in lowercase: %s" % s.lower())

# Check how a string starts
if s.startswith("Str"):
    print("String starts with 'Str'. Good!")

# Check how a string ends
if s.endswith("ome!"):
    print("String ends with 'ome!'. Good!")

# Split the string into three separate strings,
# each containing only a word
print("Split the words of the string: %s" % s.split(" "))
#Clue : s = "Strings are awesome!"<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14206128133704735, 'fraction_numerical': 0.016713091922005572, 'mean_word_length': 5.6094069529652355, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '449765', 'license': 'MIT', 'n_tokens_mistral': 1103, 'n_tokens_neox': 1068, 'n_words': 366, 'path': '2. Python - Basic String Operations.ipynb', 'repo_name': 'utsav-walia/All_Python_Topics', 'size': '3231'}