GitHub Viewer
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "m3XW1EvE9EGM",
"outputId": "a4794bba-8702-4225-da15-202cdd74754d"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"\"hello world\"\n",
" \" hello world \" \n",
"hello world \n",
"hello world\n",
"hello worldhelloworld\n",
"helloworld\n",
"hellow world\n"
]
}
],
"source": [
"print('\"hello world\"')\n",
"print(\" \\\" hello world \\\" \")\n",
"print('hello world \\nhello world')\n",
"print('hello world',end='')\n",
"print('helloworld')\n",
"# '\\n' to separate one line into two\n",
"# ,end='' to join two line into one\n",
"print('hello' + 'world')\n",
"print('hellow' , 'world')\n",
"#f-string\n",
"x=0\n",
"print(f'aaaaa{x}aaaaa')"
]
},
{
"cell_type": "code",
"source": [
"print('hello ' + input('what is your name? '))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "jyPtS6zoBxbD",
"outputId": "e23cd6ab-9d78-43f0-ba0f-d09dc51f0ded"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"what is your name: Boss\n",
"hello Boss\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"len(input('what is your name? '))\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "lha2W86728_E",
"outputId": "42d2fb7b-f92e-4e81-ce8e-d8244d2d75ad"
},
"execution_count": null,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"what is your name? boss boss\n"
]
},
{
"output_type": "execute_result",
"data": {
"text/plain": [
"9"
]
},
"metadata": {},
"execution_count": 5
}
]
},
{
"cell_type": "code",
"source": [
"#replacing the value\n",
"a=3\n",
"b=7\n",
"c=a\n",
"a=b\n",
"b=c\n",
"print('a=', a , '\\n''b=', b )"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "KB_TH2MX6tvs",
"outputId": "04028dbd-4940-4d6b-a69d-5974abda8d9b"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"a= 7 \n",
"b= 3\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# Data type basic\n",
"#String- str()\n",
"'hellow'[0] # [position]\n",
"#Integer- int()\n",
"12345\n",
"#Floating- float()\n",
"123.456\n",
"#Boolean- bool()\n",
"True\n",
"False\n",
"type() # it checks the typr of data\n",
"#string.isnumeric().upper().lower().count().find().replace().strip().split(',')\n",
"#floating.format()"
],
"metadata": {
"id": "ffm44cr2f0Vg"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"print(round(8/3,2)) # to round up/down to specific digit\n",
"print(11//99) # divides and round down\n",
"# small%big=small , big%small=remainder , small//big=0, big//small=divide down"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "wKNYeCA-hCmD",
"outputId": "56bc2899-01af-4761-b8e4-fddd113df2c9"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"2.67\n",
"0\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"if #if the condition is met then program goes to it\n",
"elif #if the above 'if' or 'elif' condition is met then this condition is not checked\n",
"else #if none of the above conditions under the last 'if' are met then program passes theough it"
],
"metadata": {
"id": "A69SdB3l61Sk"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import random\n",
"r= random.randint(0,10) #(stop,stope-1)\n",
"m= random.randrange(1,100,10)#(stop,stope-1,step)\n",
"n= random.random() #0-1\n",
"s= random.shuffle()#shuffle the order\n",
"c= random.choice()#choice one item\n",
"print(r,m,n)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "SXBqPiKfXfdE",
"outputId": "409dd667-c58f-4ac7-92e6-46460340fb37"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"1 41 0.8347738925607598\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"List= ['a','b','c','d','e']\n",
"#List[position](0to4)(-1to-5)\n",
"List.append().extend().insert(position,item).remove().pop().popleft().popright().count().sort().reverse()\n",
"#list with in a list , nested list\n",
"#add list , l= l1 + l2"
],
"metadata": {
"id": "DzMzr2OAcOap"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"range(start,stop-1,step) , range(n)#(0 to n-1)\n",
"#for i in str/range/list : (good iteration)\n",
"#while condition : (good for certain condition)"
],
"metadata": {
"id": "3Qh3mKoX35vH"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import numpy as np\n",
"ar=np.array([value]) #given array\n",
"np.zeros(size, dtype = datatype) #dtype defult float\n",
"np.one((row,col),dtype = datatype)\n",
"np.empty((row,col),dtype)\n",
"np.full((row,col), given ele) # every element in the array is fill with given ele\n",
"#ar.shape=(row,col)\n",
"#ar.size=no. of element\n",
"row=len(ar)\n",
"col=len(ar[0])\n",
"\n",
"# not much important below this for this cell\n",
"\n",
"ar.astype(new datatype) # to change the datatype\n",
"arc=ar.copy() # to coppy array\n",
"ars=ar.reshape() # change the shape of array, -1 to flatten array\n",
"\n",
"np.nditer(ar[::], flags=['buffered'], op_dtypes=['new datatype']) # iterats through all element, slicing or fl&op is optional\n",
"np.ndenumerate(ar) # gives index and element in loop\n",
"\n",
"arj=np.concatenate((a1,a2)axis).stack().hstack().vstack().dstack() # join array\n",
"ars=np.array_split(ar, parts, axis) # splits in equal parts\n",
"\n",
"aw=np.where(ar==ele) # makes an array where the elements are the index of ele\n",
"ass=np.searchsorted(ar, ele, side='') # returns the index of 1st ele\n",
"\n",
"np.sort(ar) # sorts numarically and alphabetically in 1st dimention"
],
"metadata": {
"id": "9CEl9bQhmJA4"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"import numpy as np # importing\n",
"a=np.array([1,2,3,4,5,6,7,8,9]) # creating\n",
"print(a) #calling\n",
"print(a[0]) # indexing (negative possible)\n",
"print(a[1:9:2]) # slicing [start:end:gap] (negative possible)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "eMLjnRgTrTzs",
"outputId": "65ab1198-9d18-4e51-9095-66a6abc4ad9e"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[1 2 3 4 5 6 7 8 9]\n",
"1\n",
"[2 4 6 8]\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"a2d=np.array([[1,2,3],\n",
" [4,5,6]]) # 2D array\n",
"\n",
"a3d=np.array([[[1,2,3],[4,5,6],[7,8,9]],\n",
" [[1,2,3],[4,5,6],[7,8,9]],\n",
" [[1,2,3],[4,5,6],[7,8,9]]]) # 3D array\n",
"\n",
"print(a2d)\n",
"print(a3d)\n",
"\n",
"a4d=np.array([1, 2, 3, 4], ndmin=4) # to define the dimention\n",
"print(a4d.ndim) # to check the dimention of array\n",
"print(a4d.shape) # to know how many element in each dimention\n",
"\n",
"print(a3d[1][1][1]) # indexing\n",
"print(a3d[0:1][1:2][2:3]) # slicing can also be used within indexing"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "RH5qwVsKrVVW",
"outputId": "835ea79d-b4df-411f-c99e-97c1b7b59a3b"
},
"execution_count": null,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[[1 2 3]\n",
" [4 5 6]]\n",
"[[[1 2 3]\n",
" [4 5 6]\n",
" [7 8 9]]\n",
"\n",
" [[1 2 3]\n",
" [4 5 6]\n",
" [7 8 9]]\n",
"\n",
" [[1 2 3]\n",
" [4 5 6]\n",
" [7 8 9]]]\n",
"4 (1, 1, 1, 4)\n",
"5\n",
"[]\n"
]
}
]
}
]
}