<jupyter_start><jupyter_text>Boolean VariablesBoolean values are the two constant objects False and True.They are used to represent truth values (other values can also be considered false or true).In numeric contexts (for example, when used as the argument to an arithmetic operator), they behave like the integers 0 and 1, respectively.The built-in function bool() can be used to cast any value to a Boolean, if the value can be interpreted as a truth valueThey are written as False and True, respectively.<jupyter_code>type(True)
my_str="Nikhil"
print(my_str.isalnum()) #check if all char are numbers
print(my_str.isalpha()) #check if all char in the string are alphabetic
print(my_str.isdigit()) #test if string contains digits
print(my_str.istitle()) #test if string contains title words
print(my_str.isupper()) #test if string contains upper case
print(my_str.islower()) #test if string contains lower case
print(my_str.isspace()) #test if string contains spaces
print(my_str.endswith('k')) #test if string endswith a d
print(my_str.startswith('N')) #test if string startswith H<jupyter_output>True
True
False
True
False
False
False
False
True<jupyter_text>Boolean and Logical Operators<jupyter_code>True and True
True and False
True or False
my_str="Nikhil"
str_example="Hello World"
my_str.isalpha() or str_example.isnumeric()<jupyter_output><empty_output><jupyter_text>ListsA list is a data structure in Python that is a mutable, or changeable, ordered sequence of elements. Each element or value that is inside of a list is called an item. Just as strings are defined as characters between quotes, lists are defined by having values between square brackets [ ]<jupyter_code>type([])
lst=list()
type(lst)
lst=["Maths","Physics",100,200]
len(lst)
lst[2]<jupyter_output><empty_output><jupyter_text>Append<jupyter_code>#append is used to add elements in the list
lst.append("Nikhil")
lst
lst[:]
lst[1:]
lst[1:4]<jupyter_output><empty_output><jupyter_text>Insert<jupyter_code>#insert in a specific order
lst.insert(1,"Nikhil")
lst
lst.append(["Hello","World"])
lst<jupyter_output><empty_output><jupyter_text>Extend Method<jupyter_code>lst.extend([1,2])
lst<jupyter_output><empty_output><jupyter_text>Various Operations that we perform in List<jupyter_code>lst=[1,2,3,4,5]
sum(lst)
lst*2<jupyter_output><empty_output><jupyter_text>pop() method<jupyter_code>lst.pop()
lst
lst.pop(2)
lst<jupyter_output><empty_output><jupyter_text>count() : Calculates total occurences of given element of list<jupyter_code>lst=[1,1,2,3,4,5]
lst.count(1)
len(lst)
# index() : Returns the index of first occurence. Start and end index are not necessary parameters
lst.index(3,0,4) # value, start index, end index
# Min and Max
min(lst)
max(lst)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10264780558578164, 'fraction_numerical': 0.011606819006166122, 'mean_word_length': 7.460122699386503, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '239922', 'license': 'MIT', 'n_tokens_mistral': 932, 'n_tokens_neox': 910, 'n_words': 293, 'path': 'Basics/.ipynb_checkpoints/#1 List and Boolean Variables-checkpoint.ipynb', 'repo_name': 'nikkkhil067/Machine-Learning', 'size': '2757'}