Skip to content

Instantly share code, notes, and snippets.

Avatar

Rahul Banerjee rahulbanerjee26

View GitHub Profile
View index.ts
interface userType{
id: number,
name: string,
email: string,
age?:number
}
let user: userType = {
id: 10,
name:'Rahul',
View index.ts
// Declaring object with custom type
let user:{id:number,name:string,email:string} = {
id:10,
name:'Rahul',
email:'a@g.com'
}
console.log(user.id)
// 10
console.log(user.number)
View index.ts
// Declaring object with type Record<string,string>
let user:Record<string,string>={
name: 'Rahul',
email: 'a@g.com'
}
console.log(user.name)
// Rahul
console.log(user.number)
// undefined
View index.ts
// Declaring object with type Record<string,any>
let user:Record<string,any>={
name: 'Rahul',
email: 'a@g.com'
}
console.log(user.name)
// Rahul
console.log(user.number)
// undefined
View index.ts
//Declaring object with the type object
let user:Object = {
id: 10,
name: 'Rahul',
email: 'a@g.com'
}
console.log(user.name)
// error TS2339: Property 'name' does not exist on type 'object'.
user.age = 20
View index.ts
//Declaring object with type any
let user:any = {
id: 10,
name: 'Rahul',
email: 'a@g.com'
}
console.log(user.name)
//Rahul
View index.ts
//Declaring object with no types
let user = {
id: 10,
name: 'Rahul',
email: 'a@g.com'
}
console.log(user.name)
// Rahul
View data.js
{
'name' : 'Rahul',
'age': 22,
'city': 'Toronto',
'sex': 'Male'
}
View __init__.py
neighbors = space.nearest_neighbors(key="Kizumonogatari II: Nekketsu-hen", num=5)
for neighbor in neighbors:
print( neighbor )
print( anime_list[anime_list['name'] == neighbor]['genre'] )
'''
Output
Durarara!!
View __init__.py
anime_to_recommend_for = 'Kizumonogatari II: Nekketsu-hen'
print(
anime_list[anime_list['name'] == anime_to_recommend_for]['genre']
)
'''
Genres
Action, Mystery, Supernatural, Vampire
'''